fragment-api-sdk 0.1.0__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.
- fragment_api_sdk/__init__.py +179 -0
- fragment_api_sdk/ton_helper.mjs +99 -0
- fragment_api_sdk/verify.py +106 -0
- fragment_api_sdk-0.1.0.dist-info/METADATA +49 -0
- fragment_api_sdk-0.1.0.dist-info/RECORD +7 -0
- fragment_api_sdk-0.1.0.dist-info/WHEEL +5 -0
- fragment_api_sdk-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"""Fragment API — Python SDK with local signing.
|
|
2
|
+
|
|
3
|
+
The seed is used ONLY on this machine: to derive the TON account object
|
|
4
|
+
(public parts are sent to the API) and to sign prepared payments after
|
|
5
|
+
the full verification checklist passes. It is never transmitted.
|
|
6
|
+
|
|
7
|
+
Signing/derivation run through the bundled Node helper (ton_helper.mjs,
|
|
8
|
+
@ton/ton) — Node 18+ must be available. Spend limits are MANDATORY:
|
|
9
|
+
nothing is signed until the caller sets per-order limits.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
api = FragmentAPI(api_key="mfrag_…", cookies={...}, seed="24 words…",
|
|
13
|
+
max_ton_per_order=5_000_000_000)
|
|
14
|
+
order = api.buy_stars("@durov", 100) # verified + signed locally
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
import os
|
|
19
|
+
import subprocess
|
|
20
|
+
import sys
|
|
21
|
+
import time
|
|
22
|
+
import urllib.request
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
from . import verify as _verify # packaged layout (PyPI)
|
|
26
|
+
except ImportError: # repo layout: shared checklist lives in ../engine
|
|
27
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "engine"))
|
|
28
|
+
import verify as _verify # noqa: E402
|
|
29
|
+
|
|
30
|
+
DEFAULT_BASE = "https://fragment-api.mboxcommunity.org"
|
|
31
|
+
HELPER = os.path.join(os.path.dirname(__file__), "ton_helper.mjs")
|
|
32
|
+
if not os.path.exists(HELPER): # repo layout fallback
|
|
33
|
+
HELPER = os.path.join(os.path.dirname(__file__), "..", "engine",
|
|
34
|
+
"ton_helper.mjs")
|
|
35
|
+
|
|
36
|
+
# Our service fee wallet, pinned in the SDK (a server can never rename
|
|
37
|
+
# it): the operator's Fragment wallet.
|
|
38
|
+
PINNED_SERVICE_WALLETS = {
|
|
39
|
+
"UQC3YLJkrL4hWykTbLNfR0oGjDm95f2wBhmllW5GdItX7fTA",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class SDKError(Exception):
|
|
44
|
+
def __init__(self, code, message=""):
|
|
45
|
+
super().__init__(f"{code}: {message}")
|
|
46
|
+
self.code = code
|
|
47
|
+
self.message = message
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _helper(cmd, payload):
|
|
51
|
+
out = subprocess.run(["node", HELPER, cmd, json.dumps(payload)],
|
|
52
|
+
capture_output=True, text=True, timeout=60)
|
|
53
|
+
if out.returncode != 0:
|
|
54
|
+
raise SDKError("TON_HELPER_FAILED", (out.stderr or out.stdout)[:200])
|
|
55
|
+
return json.loads(out.stdout)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _tonapi_seqno(address_friendly):
|
|
59
|
+
url = f"https://tonapi.io/v2/blockchain/accounts/{address_friendly}"
|
|
60
|
+
req = urllib.request.Request(url, headers={"Accept": "application/json"})
|
|
61
|
+
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
62
|
+
data = json.loads(resp.read())
|
|
63
|
+
return int(data.get("seqno") or 0)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class FragmentAPI:
|
|
67
|
+
def __init__(self, api_key, cookies, seed, wallet_type="v4r2",
|
|
68
|
+
base=DEFAULT_BASE, max_ton_per_order=None,
|
|
69
|
+
max_usdt_per_order=None, max_fee_percent=1.0):
|
|
70
|
+
if max_ton_per_order is None and max_usdt_per_order is None:
|
|
71
|
+
raise SDKError("LIMITS_REQUIRED",
|
|
72
|
+
"set max_ton_per_order / max_usdt_per_order")
|
|
73
|
+
self.base = base.rstrip("/")
|
|
74
|
+
self.api_key = api_key
|
|
75
|
+
self.cookies = cookies
|
|
76
|
+
self.seed = seed
|
|
77
|
+
self.wallet_type = wallet_type
|
|
78
|
+
self.max_ton_per_order = max_ton_per_order
|
|
79
|
+
self.max_usdt_per_order = max_usdt_per_order
|
|
80
|
+
self.max_fee_percent = max_fee_percent
|
|
81
|
+
self._session_token = None
|
|
82
|
+
acct = _helper("derive", {"seed": seed, "wallet_type": wallet_type})
|
|
83
|
+
self.account = {"address": acct["address"],
|
|
84
|
+
"chain": "-239",
|
|
85
|
+
"walletStateInit": acct["state_init"],
|
|
86
|
+
"publicKey": acct["public_key"]}
|
|
87
|
+
self._account_full = acct
|
|
88
|
+
|
|
89
|
+
# ---------- HTTP ----------
|
|
90
|
+
def _call(self, method, path, body=None, auth=False):
|
|
91
|
+
req = urllib.request.Request(self.base + path, method=method)
|
|
92
|
+
req.add_header("Content-Type", "application/json")
|
|
93
|
+
if auth:
|
|
94
|
+
if not self._session_token:
|
|
95
|
+
self._open_session()
|
|
96
|
+
req.add_header("Authorization", f"Bearer {self._session_token}")
|
|
97
|
+
data = json.dumps(body).encode() if body is not None else None
|
|
98
|
+
try:
|
|
99
|
+
with urllib.request.urlopen(req, data=data, timeout=60) as resp:
|
|
100
|
+
return json.loads(resp.read())
|
|
101
|
+
except urllib.error.HTTPError as e:
|
|
102
|
+
raw = e.read()
|
|
103
|
+
try:
|
|
104
|
+
payload = json.loads(raw)
|
|
105
|
+
except ValueError:
|
|
106
|
+
raise SDKError("HTTP_ERROR", f"status {e.code}")
|
|
107
|
+
err = payload.get("error") or {}
|
|
108
|
+
raise SDKError(err.get("error_code", "HTTP_ERROR"),
|
|
109
|
+
err.get("message", ""))
|
|
110
|
+
except Exception as e:
|
|
111
|
+
raise SDKError("NETWORK_ERROR", str(e)[:200])
|
|
112
|
+
|
|
113
|
+
def _open_session(self):
|
|
114
|
+
out = self._call("POST", "/api/v1/session", {
|
|
115
|
+
"api_key": self.api_key, "cookies": self.cookies,
|
|
116
|
+
"account": self.account})
|
|
117
|
+
if not out.get("success"):
|
|
118
|
+
err = out.get("error") or {}
|
|
119
|
+
raise SDKError(err.get("error_code", "AUTH_FAILED"),
|
|
120
|
+
err.get("message", ""))
|
|
121
|
+
self._session_token = out["session_token"]
|
|
122
|
+
|
|
123
|
+
# ---------- public ----------
|
|
124
|
+
def buy_stars(self, username, amount, currency="TON",
|
|
125
|
+
idempotency_key=None):
|
|
126
|
+
return self._buy("stars", username, currency,
|
|
127
|
+
amount=int(amount), months=None,
|
|
128
|
+
idempotency_key=idempotency_key)
|
|
129
|
+
|
|
130
|
+
def buy_premium(self, username, months, currency="TON",
|
|
131
|
+
idempotency_key=None):
|
|
132
|
+
return self._buy("premium", username, currency,
|
|
133
|
+
amount=None, months=int(months),
|
|
134
|
+
idempotency_key=idempotency_key)
|
|
135
|
+
|
|
136
|
+
def get_order(self, order_id):
|
|
137
|
+
out = self._call("GET", f"/api/v1/orders/{order_id}", auth=True)
|
|
138
|
+
return out.get("order")
|
|
139
|
+
|
|
140
|
+
# ---------- flow ----------
|
|
141
|
+
def _buy(self, product, username, currency, amount, months,
|
|
142
|
+
idempotency_key):
|
|
143
|
+
path = "/api/v1/premium/buy" if product == "premium" \
|
|
144
|
+
else "/api/v1/stars/buy"
|
|
145
|
+
out = self._call("POST", path, {
|
|
146
|
+
"username": username, "currency": currency, "amount": amount,
|
|
147
|
+
"months": months, "idempotency_key": idempotency_key},
|
|
148
|
+
auth=True)
|
|
149
|
+
if not out.get("success"):
|
|
150
|
+
err = out.get("error") or {}
|
|
151
|
+
raise SDKError(err.get("error_code", "ORDER_FAILED"),
|
|
152
|
+
err.get("message", ""))
|
|
153
|
+
order, payment = out["order"], out["payment"]
|
|
154
|
+
|
|
155
|
+
# THE trust boundary: verify before signing (checklist in
|
|
156
|
+
# engine/verify.py). Any failure raises and nothing is sent.
|
|
157
|
+
_verify.verify_payment(
|
|
158
|
+
{"product": product, "currency": currency}, payment,
|
|
159
|
+
own_wallet_address=self.account["address"],
|
|
160
|
+
own_usdt_wallet=None, # USDT payload check: see note in verify
|
|
161
|
+
pinned_service_wallets=PINNED_SERVICE_WALLETS,
|
|
162
|
+
max_fee_percent=self.max_fee_percent,
|
|
163
|
+
max_ton_per_order=self.max_ton_per_order,
|
|
164
|
+
max_usdt_per_order=self.max_usdt_per_order)
|
|
165
|
+
|
|
166
|
+
seqno = _tonapi_seqno(self._account_full["address_friendly"])
|
|
167
|
+
valid_until = min(int(payment["valid_until"]),
|
|
168
|
+
int(time.time()) + _verify.MAX_SIGNED_TTL_S)
|
|
169
|
+
signed = _helper("sign", {
|
|
170
|
+
"seed": self.seed, "wallet_type": self.wallet_type,
|
|
171
|
+
"seqno": seqno, "valid_until": valid_until,
|
|
172
|
+
"messages": payment["messages"]})
|
|
173
|
+
out = self._call("POST", f"/api/v1/orders/{order['id']}/submit",
|
|
174
|
+
{"boc": signed["boc"]}, auth=True)
|
|
175
|
+
if not out.get("success"):
|
|
176
|
+
err = out.get("error") or {}
|
|
177
|
+
raise SDKError(err.get("error_code", "SUBMIT_FAILED"),
|
|
178
|
+
err.get("message", ""))
|
|
179
|
+
return out["order"]
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// TON wallet helper for the Fragment API SDK (Node, @ton/ton).
|
|
2
|
+
//
|
|
3
|
+
// Commands (JSON in via argv[3] or stdin; JSON out on stdout):
|
|
4
|
+
// derive {seed: "24 words…", wallet_type: "v4r2"|"w5"}
|
|
5
|
+
// -> {address (raw 0:…), address_friendly, public_key (hex),
|
|
6
|
+
// state_init (base64 BoC)} — the Fragment `account` object
|
|
7
|
+
// sign {seed, wallet_type, seqno, valid_until, messages:
|
|
8
|
+
// [{address, amount (nanoton string), payload? (base64 BoC),
|
|
9
|
+
// stateInit? (base64 BoC)}]}
|
|
10
|
+
// -> {boc} — signed external message, send mode 3 per message
|
|
11
|
+
//
|
|
12
|
+
// The seed is used in-process only and never printed. Module resolution:
|
|
13
|
+
// ./node_modules, $TON_MODULES, then the MBOX forwarder project (dev).
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import path from "node:path";
|
|
16
|
+
|
|
17
|
+
const candidates = [
|
|
18
|
+
path.resolve(process.cwd(), "node_modules"),
|
|
19
|
+
process.env.TON_MODULES,
|
|
20
|
+
"/home/hatch/workspace/mbox-hub-forwarder/node_modules",
|
|
21
|
+
].filter(Boolean);
|
|
22
|
+
|
|
23
|
+
let ton, crypto;
|
|
24
|
+
for (const base of candidates) {
|
|
25
|
+
try {
|
|
26
|
+
const req = createRequire(path.join(base, "noop.js"));
|
|
27
|
+
ton = req("@ton/ton");
|
|
28
|
+
crypto = req("@ton/crypto");
|
|
29
|
+
break;
|
|
30
|
+
} catch { /* try next */ }
|
|
31
|
+
}
|
|
32
|
+
if (!ton) {
|
|
33
|
+
console.error(JSON.stringify({ error: "TON_MODULES_NOT_FOUND" }));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { WalletContractV4, WalletContractV5R1, internal, external, Address, Cell, beginCell } = ton;
|
|
38
|
+
const { mnemonicToPrivateKey } = crypto;
|
|
39
|
+
|
|
40
|
+
async function walletFromSeed(seed, walletType) {
|
|
41
|
+
const words = String(seed).trim().split(/\s+/);
|
|
42
|
+
const keyPair = await mnemonicToPrivateKey(words);
|
|
43
|
+
const workchain = 0;
|
|
44
|
+
const wallet = walletType === "w5"
|
|
45
|
+
? WalletContractV5R1.create({ workchain, publicKey: keyPair.publicKey })
|
|
46
|
+
: WalletContractV4.create({ workchain, publicKey: keyPair.publicKey });
|
|
47
|
+
return { wallet, keyPair };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function accountObject(wallet, keyPair) {
|
|
51
|
+
const init = wallet.init;
|
|
52
|
+
const stateInit = beginCell()
|
|
53
|
+
.storeUint(0b00110, 5)
|
|
54
|
+
.storeRef(init.code)
|
|
55
|
+
.storeRef(init.data)
|
|
56
|
+
.endCell();
|
|
57
|
+
return {
|
|
58
|
+
address: wallet.address.toRawString(),
|
|
59
|
+
address_friendly: wallet.address.toString(),
|
|
60
|
+
public_key: keyPair.publicKey.toString("hex"),
|
|
61
|
+
state_init: stateInit.toBoc().toString("base64"),
|
|
62
|
+
chain: "-239",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function main() {
|
|
67
|
+
const cmd = process.argv[2];
|
|
68
|
+
const input = JSON.parse(process.argv[3] || "{}");
|
|
69
|
+
if (cmd === "derive") {
|
|
70
|
+
const { wallet, keyPair } = await walletFromSeed(input.seed, input.wallet_type || "v4r2");
|
|
71
|
+
console.log(JSON.stringify(accountObject(wallet, keyPair)));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (cmd === "sign") {
|
|
75
|
+
const { wallet, keyPair } = await walletFromSeed(input.seed, input.wallet_type || "v4r2");
|
|
76
|
+
const messages = (input.messages || []).map((m) => internal({
|
|
77
|
+
to: Address.parse(m.address),
|
|
78
|
+
value: BigInt(m.amount),
|
|
79
|
+
body: m.payload ? Cell.fromBase64(m.payload) : undefined,
|
|
80
|
+
init: m.stateInit ? Cell.fromBase64(m.stateInit) : undefined,
|
|
81
|
+
}));
|
|
82
|
+
const transfer = wallet.createTransfer({
|
|
83
|
+
seqno: input.seqno,
|
|
84
|
+
secretKey: keyPair.secretKey,
|
|
85
|
+
messages,
|
|
86
|
+
sendMode: 3,
|
|
87
|
+
timeout: input.valid_until,
|
|
88
|
+
});
|
|
89
|
+
console.log(JSON.stringify({ boc: transfer.toBoc().toString("base64") }));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
console.error(JSON.stringify({ error: "UNKNOWN_COMMAND" }));
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main().catch((e) => {
|
|
97
|
+
console.error(JSON.stringify({ error: String(e && e.message || e) }));
|
|
98
|
+
process.exit(1);
|
|
99
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""Prepared-payment verification — the local-signing safety checklist.
|
|
2
|
+
|
|
3
|
+
Shared by the server (to sanity-check what it prepared) and by the
|
|
4
|
+
customer SDK (the real trust boundary: the SDK runs this BEFORE signing,
|
|
5
|
+
on the customer's own machine). Any failure raises UntrustedPayment and
|
|
6
|
+
nothing is signed or sent.
|
|
7
|
+
|
|
8
|
+
Checklist adapted from the public v3 local-signing design — see
|
|
9
|
+
docs/research-purchase-flow.md section (c).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# Fragment's own receiving addresses, pinned in code (never trusted
|
|
13
|
+
# from a server response). Source: v3 guide via research doc (c)(3).
|
|
14
|
+
PINNED_FRAGMENT_ADDRESSES = {
|
|
15
|
+
"UQBAjaOyi2wGWlk-EDkSabqqnF-MrrwMadnwqrurKpkla4QB",
|
|
16
|
+
"UQCFJEP4WZ_mpdo0_kMEmsTgvrMHG7K_tWY16pQhKHwoOtFz",
|
|
17
|
+
"UQBeab7D38RIwypegbN7YZgQzwDbb8QfMMwY8ouJc3qPl4CJ",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
DEFAULT_MAX_FEE_PERCENT = 0.01 # our service fee (owner, 2026-11-29)
|
|
21
|
+
HARD_MAX_FEE_PERCENT = 5.0 # SDK-side absolute cap, user-configurable
|
|
22
|
+
MAX_SIGNED_TTL_S = 120 # signed message lifetime clamp
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class UntrustedPayment(Exception):
|
|
26
|
+
def __init__(self, check, detail=""):
|
|
27
|
+
super().__init__(f"UNTRUSTED_PAYMENT [{check}] {detail}")
|
|
28
|
+
self.code = "UNTRUSTED_PAYMENT"
|
|
29
|
+
self.check = check
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def verify_payment(order, payment, *, own_wallet_address,
|
|
33
|
+
own_usdt_wallet=None, pinned_service_wallets,
|
|
34
|
+
max_fee_percent=DEFAULT_MAX_FEE_PERCENT,
|
|
35
|
+
max_ton_per_order=None, max_usdt_per_order=None):
|
|
36
|
+
"""Verify a prepared payment against the client's own order.
|
|
37
|
+
|
|
38
|
+
order: {product, amount|months, username, currency, payment_method}
|
|
39
|
+
payment: {valid_until, network, from, messages:[{address, amount,
|
|
40
|
+
payload?, role}]} — amounts are integer strings in the
|
|
41
|
+
currency's smallest unit (nanoton / USDT 1e-6).
|
|
42
|
+
Returns a summary dict {fragment_nano, fee_nano, total_nano} on success.
|
|
43
|
+
Raises UntrustedPayment on any failed check.
|
|
44
|
+
"""
|
|
45
|
+
msgs = payment.get("messages") or []
|
|
46
|
+
|
|
47
|
+
# (2) payer binding + network
|
|
48
|
+
if payment.get("network") not in ("-239", None):
|
|
49
|
+
raise UntrustedPayment("network", str(payment.get("network")))
|
|
50
|
+
if payment.get("from") and payment["from"] != own_wallet_address:
|
|
51
|
+
raise UntrustedPayment("payer", "payment.from is not the own wallet")
|
|
52
|
+
|
|
53
|
+
# (1) structure: KYC orders carry fragment (+ optional fee) legs only.
|
|
54
|
+
roles = [m.get("role") for m in msgs]
|
|
55
|
+
if "middle" in roles:
|
|
56
|
+
raise UntrustedPayment("structure", "middle leg in a KYC order")
|
|
57
|
+
if roles.count("fragment") != 1:
|
|
58
|
+
raise UntrustedPayment("structure", f"roles={roles}")
|
|
59
|
+
if any(r not in ("fragment", "fee") for r in roles):
|
|
60
|
+
raise UntrustedPayment("structure", f"unknown role in {roles}")
|
|
61
|
+
|
|
62
|
+
frag = msgs[roles.index("fragment")]
|
|
63
|
+
fee = msgs[roles.index("fee")] if "fee" in roles else None
|
|
64
|
+
|
|
65
|
+
currency = (order.get("currency") or "TON").upper()
|
|
66
|
+
if currency == "TON":
|
|
67
|
+
# (3) fragment leg must target a pinned Fragment address
|
|
68
|
+
if frag.get("address") not in PINNED_FRAGMENT_ADDRESSES:
|
|
69
|
+
raise UntrustedPayment("fragment_address", str(frag.get("address")))
|
|
70
|
+
else: # USDT: message goes to the client's OWN jetton wallet
|
|
71
|
+
# (4) own USDT wallet only
|
|
72
|
+
if own_usdt_wallet is None:
|
|
73
|
+
raise UntrustedPayment("usdt_wallet", "own USDT wallet unknown")
|
|
74
|
+
if frag.get("address") != own_usdt_wallet:
|
|
75
|
+
raise UntrustedPayment("usdt_wallet", str(frag.get("address")))
|
|
76
|
+
# NOTE: the Fragment destination inside the jetton payload is
|
|
77
|
+
# verified by the SDK's payload parser (SDK layer), not here.
|
|
78
|
+
|
|
79
|
+
frag_amount = int(frag.get("amount") or 0)
|
|
80
|
+
fee_amount = int(fee.get("amount") or 0) if fee else 0
|
|
81
|
+
|
|
82
|
+
if fee is not None:
|
|
83
|
+
# (5) fee leg only to a pinned service wallet
|
|
84
|
+
if fee.get("address") not in pinned_service_wallets:
|
|
85
|
+
raise UntrustedPayment("fee_address", str(fee.get("address")))
|
|
86
|
+
# (6) fee ceiling, same currency
|
|
87
|
+
if frag_amount > 0 and fee_amount * 100.0 / frag_amount > max_fee_percent:
|
|
88
|
+
raise UntrustedPayment(
|
|
89
|
+
"fee_ceiling",
|
|
90
|
+
f"fee {fee_amount} > {max_fee_percent}% of {frag_amount}")
|
|
91
|
+
|
|
92
|
+
# (7) mandatory per-order spend limits
|
|
93
|
+
total = frag_amount + fee_amount
|
|
94
|
+
if currency == "TON":
|
|
95
|
+
if max_ton_per_order is None:
|
|
96
|
+
raise UntrustedPayment("limits", "max_ton_per_order not set")
|
|
97
|
+
if total > int(max_ton_per_order):
|
|
98
|
+
raise UntrustedPayment("limits", f"total {total} over TON limit")
|
|
99
|
+
else:
|
|
100
|
+
if max_usdt_per_order is None:
|
|
101
|
+
raise UntrustedPayment("limits", "max_usdt_per_order not set")
|
|
102
|
+
if total > int(max_usdt_per_order):
|
|
103
|
+
raise UntrustedPayment("limits", f"total {total} over USDT limit")
|
|
104
|
+
|
|
105
|
+
return {"fragment_amount": frag_amount, "fee_amount": fee_amount,
|
|
106
|
+
"total_amount": total, "currency": currency}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fragment-api-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Fragment API Python SDK — Telegram Stars & Premium with local signing (your seed never leaves your server)
|
|
5
|
+
Author: MBOX Community
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://fragment.mboxcommunity.org
|
|
8
|
+
Project-URL: Documentation, https://fragment.mboxcommunity.org/docs.html
|
|
9
|
+
Project-URL: Repository, https://github.com/mboxcommunity/fragment-api
|
|
10
|
+
Keywords: telegram,fragment,stars,premium,ton
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# Fragment API — Python SDK
|
|
18
|
+
|
|
19
|
+
Buy Telegram Stars and Premium through [Fragment API](https://fragment.mboxcommunity.org) with **local signing**: the service prepares each payment, this SDK verifies it against a pinned checklist and signs it on your machine. Your wallet seed never leaves your server.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
pip install fragment-api-sdk
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires Python 3.10+ and Node 18+ (used by the bundled TON signing helper).
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from fragment_api_sdk import FragmentAPI
|
|
33
|
+
|
|
34
|
+
api = FragmentAPI(
|
|
35
|
+
api_key="mfrag_…", # issued by the service admin
|
|
36
|
+
cookies={"stel_ssid": "…", "stel_dt": "…", "stel_token": "…"}, # your Fragment session
|
|
37
|
+
seed="word1 word2 … word24", # used ONLY locally — never transmitted
|
|
38
|
+
max_ton_per_order=5_000_000_000, # mandatory spend limit (nanotons)
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
order = api.buy_stars("@durov", 100) # verify → sign locally → submit
|
|
42
|
+
print(order["status"]) # success
|
|
43
|
+
|
|
44
|
+
order = api.buy_premium("@durov", 12) # 3 | 6 | 12 months
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Spend limits are mandatory — the SDK refuses to operate without them, and refuses to sign any payment that fails verification (order mismatch, unpinned destination, fee above cap, expired payment).
|
|
48
|
+
|
|
49
|
+
Full documentation: https://fragment.mboxcommunity.org/docs.html
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
fragment_api_sdk/__init__.py,sha256=lWs4NkzlF8Maf4GhPBh5p2qO0mFjhMsFBj5NWeIxtiY,7639
|
|
2
|
+
fragment_api_sdk/ton_helper.mjs,sha256=9sq8YpgcblNq-9XdNPRVfEaYzZhrTahLJT9pBTs-ytA,3478
|
|
3
|
+
fragment_api_sdk/verify.py,sha256=FP4gvYDAUfzAMlLAtYYXBv7OY2CX1KcrGkcIHX7IUFc,4909
|
|
4
|
+
fragment_api_sdk-0.1.0.dist-info/METADATA,sha256=Lnmol33oKxrVtuPfmxoFVIRTwyr4c7p1Y4v8ppI-yI4,2005
|
|
5
|
+
fragment_api_sdk-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
fragment_api_sdk-0.1.0.dist-info/top_level.txt,sha256=WhhGPrORk37qnP8cYwnpTy5Tvb7P_RKmG6FZwPAPkYg,17
|
|
7
|
+
fragment_api_sdk-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fragment_api_sdk
|