A simple language for non-custodial swaps
Project description
Sophi
A simple language for Bitcoin non-custodial smart contracts.
Sophi has no runtime, no blockchain execution, and no custody of funds. You describe what a fair exchange looks like — and Sophi proves it is mathematically valid.
Install
pip install sophi
Write a swap
Describe who has what before, and who has what after:
swap {
before:
alice = 0.5 BTC
bob = 50000 USDT
after:
alice = 50000 USDT
bob = 0.5 BTC
}
Run:
sophi compile trade.sph
Sophi verifies: BTC before == BTC after, USDT before == USDT after. If the math holds, it produces a valid proof. If not, clear error.
Transfer syntax
Same swap, different style:
swap {
transfer 0.5 BTC from alice to bob
transfer 50000 USDT from bob to alice
}
Three or more participants
swap {
transfer 0.5 BTC from alice to carol
transfer 50000 USDT from bob to alice
transfer 1 ETH from carol to bob
}
Any number of participants. All verified atomically.
What the proof looks like
{
"swap_id": "f970dc4b...",
"status": "valid",
"conservation": {
"BTC": { "before": "0.5", "after": "0.5" },
"USDT": { "before": "50000", "after": "50000" }
},
"delta": {
"alice": { "BTC": "-0.5", "USDT": "+50000" },
"bob": { "BTC": "+0.5", "USDT": "-50000" }
},
"htlc": {
"secret_hash": "a3f8c2...",
"timeout_blocks": 144,
"legs": [
{ "from": "alice", "to": "bob", "asset": "BTC", "amount": "0.5" },
{ "from": "bob", "to": "alice", "asset": "USDT", "amount": "50000" }
]
}
}
Signatures are external
The .sph file never contains signatures or private keys.
After compiling, each party signs the swap_id using their own Bitcoin wallet:
{
"swap_id": "f970dc4b...",
"signatures": {
"alice": { "address": "bc1qalice...", "signature": "H7f8c2..." },
"bob": { "address": "bc1qbob...", "signature": "K9d3e1..." }
}
}
Then verify:
from sophi import compile_source, verify_proof
compiled = compile_source(open("trade.sph").read())
result = verify_proof(compiled, proof_json)
# result["status"] == "signatures_valid"
Rules that never change
- 1 BTC is never equal to 1 USDT — each asset verified separately
- No value is ever created or destroyed
- Funds never leave the participants control
- No on-chain execution — Sophi only verifies, never executes
License
Business Source License 1.1 — converts to Apache 2.0 after 4 years.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sophi-0.2.7.tar.gz.
File metadata
- Download URL: sophi-0.2.7.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
639e5eb8d46045292f80c85bbace14a7ce6a5d719d5537759ba451a2acbc282c
|
|
| MD5 |
206139cc316ec165d9f392de94d34706
|
|
| BLAKE2b-256 |
e3afb4f890fe81a01b76caf2df69ff2e38d91032f2435ea499bf0a7afd25bacb
|
File details
Details for the file sophi-0.2.7-py3-none-any.whl.
File metadata
- Download URL: sophi-0.2.7-py3-none-any.whl
- Upload date:
- Size: 21.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
734a7a72b65fbeade8a0b503a5eb22a10eef4557ab150dcbfcdb3f1c73055ca2
|
|
| MD5 |
6e6c0c47deca4eec40e0336dc2120237
|
|
| BLAKE2b-256 |
3c3b53c64a9d02cb3b9bce5a7278e0f00642716240bf9f826b5e411de58c1920
|