Skip to main content

Python SDK for Themis — TON-native sealed-bid threshold-decryption mechanism. Encrypt bids, decode events, drive a chamber. TSA-audited zero findings.

Project description

titon-network-themis-sdk

Python SDK for Themis — a TON-native sealed-bid threshold-decryption mechanism on top of Atlas (BLS group key) and ForgeTON (stake + slash). 1:1 surface parity with the TypeScript SDK (@titon-network/themis-sdk), snake_case mirror.

🛡️ TSA-audited — the contracts behind this SDK are static-analysis clean (zero findings). Full posture: ../../AUDIT.md.

What this gives you

  • Sealed-bid auctions, MEV-resistant DEX swaps, confidential governance — encrypt user intents under Atlas's group key, batch-decrypt off-chain via operator threshold, dispatch to your consumer contract.
  • ThemisFactory + ThemisChamber wrappers — every send_* + get_* method, deterministic state-init derivation, bundled compiled bytecode.
  • Bidder cryptoencrypt_bid() produces a (c1, aead_cell) pair ready for SubmitCiphertext. ChaCha20-Poly1305 over an ElGamal-on-G1 KEM.
  • Consumer cryptodecode_reveal_callback() + decrypt_bid() recover the original bidder plaintext from a RevealCallback. Integrity is by AEAD MAC: a dishonest D is ignored.
  • Typed event decoder — 16 dataclasses covering every EVT_* opcode. For indexers, monitors, and tests.
  • SealedLimitOrder — reference Jetton↔Jetton sealed-bid call-auction consumer with its own event decoder + plaintext codec.

Install

pip install titon-network-themis-sdk

Bidder flow

from pytoniq import LiteBalancer
from pytoniq_core import Address
from themis_sdk import (
    THEMIS_TESTNET,
    ThemisChamber,
    encrypt_bid,
)

# Pick a chamber (your protocol's chamber address comes from DeployChamber).
chamber = ThemisChamber.create_from_address(
    THEMIS_TESTNET.slo_chamber,
    client=LiteBalancer.from_testnet_config(trust_level=2),
)

# Read the chamber's cached group key + current round.
gk = await chamber.get_group_key()
round_state = await chamber.get_current_round()

# Encrypt your bid plaintext (opaque to the chamber — the consumer parses it).
plaintext = b"protocol-specific bid bytes; for SealedLimitOrder see encode_bid_plaintext"

bid = encrypt_bid(
    plaintext=plaintext,
    group_pk=gk.group_pk,
    chamber=chamber.address,
    round_id=round_state.round_id,
)

# Submit. `value` covers the chamber's `submitFee + minXcGas + gas headroom`.
await chamber.send_submit_ciphertext(
    wallet,
    value=200_000_000,  # 0.2 TON; tune via chamber.get_config().submit_fee
    query_id=42,
    c1=bid.c1,
    aead_cell=bid.aead_cell,
)

Consumer flow (Tolk-side dispatch is yours; Python decodes the callback)

from themis_sdk import decode_reveal_callback, decrypt_bid

decoded = decode_reveal_callback(reveal_callback_body)
for b in decoded.bids:
    plaintext = decrypt_bid(
        aead_cell=b.aead_ct,
        c1=b.c1,
        d=b.d,
        chamber=decoded.chamber,
        round_id=decoded.round_id,
    )
    # plaintext is your protocol's bid bytes — parse + dispatch in your consumer.

Operator-side reveal (for tests / sandbox)

from themis_sdk import build_reveal, BuildRevealArgs, RevealEntryInput, random_group_key, group_decrypt, new_ephemeral

gk = random_group_key()      # solo mode
eph = new_ephemeral()
D = group_decrypt(eph.c1, gk.sk)

built = build_reveal(BuildRevealArgs(
    chamber=chamber.address,
    round_id=1,
    group_epoch=1,
    entries=[RevealEntryInput(idx=0, c1=eph.c1, d=D)],
    group_key=gk,
))

await chamber.send_reveal_round(
    operator_wallet,
    value=500_000_000,
    signed_data_ref=built.signed_data_ref,
    decryptions_ref=built.decryptions_ref,
    agg_sig_ref=built.agg_sig_ref,
)

When to reach for which SDK

  • TypeScript (@titon-network/themis-sdk) — canonical. Has the full surface plus the @ton/sandbox testing helpers. Required for end-to-end probes + scaffolded Tolk consumers.
  • Python (titon-network-themis-sdk, this package) — for dapp builders / indexers / off-chain operator daemons written in Python. Same ThemisFactory / ThemisChamber wrappers, same crypto primitives (py_ecc.bls.G2ProofOfPossession matches noble-curves DST byte-for-byte), same error explainer.

When editing one, mirror the other. See ../../CLAUDE.md for the workspace mirror checklist; AGENTS.md for the per-file map.

Further reading

  • AGENTS.md — SDK navigator + mirror checklist
  • skills/ — persona-grouped agent playbooks (bidder, integrate-consumer, operator-helpers, deploy-chamber, debug)
  • ../../CLAUDE.md — Themis architecture, opcode + error ranges, trust model
  • ../../PLAN.md — design rationale + execution plan
  • ../../AUDIT.md — TSA static-analysis audit posture

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

titon_network_themis_sdk-0.3.0.tar.gz (69.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

titon_network_themis_sdk-0.3.0-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

Details for the file titon_network_themis_sdk-0.3.0.tar.gz.

File metadata

  • Download URL: titon_network_themis_sdk-0.3.0.tar.gz
  • Upload date:
  • Size: 69.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for titon_network_themis_sdk-0.3.0.tar.gz
Algorithm Hash digest
SHA256 1f46299450628b1daf8fcfe2cf803b0d90a6c797742b662c67bf5135c78b8400
MD5 08e853f828c6c3d90096b795921bbe98
BLAKE2b-256 1cfb4753f8d3fdd5f9f04c8ff9690db5aac825f69d266065257b7af737a29eaf

See more details on using hashes here.

File details

Details for the file titon_network_themis_sdk-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: titon_network_themis_sdk-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 54.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for titon_network_themis_sdk-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c67836bb60d400790c21a2bf275591be786da87a84c0e393725f55bdc38a6312
MD5 51f3dec77155dae761e825b899651a4c
BLAKE2b-256 34d429c073d19f9062bbd87e25aa2fc124697c0d9161bac59cbb9c6e0fe12485

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page