A simple language for non-custodial swaps
Project description
Sophi
A simple language for non-custodial value swaps.
Sophi has no runtime, no blockchain execution, and no custody of funds. You describe the swap. Sophi verifies the math and produces a portable proof.
Install
pip install sophi
Write a swap (from-to)
swap {
transfer 0.5 BTC from alice to bob
transfer 50000 USDT from bob to alice
}
Save as trade.sph and run:
sophi compile trade.sph
Before/after still works
swap {
before:
alice = 0.5 BTC
bob = 50000 USDT
after:
alice = 50000 USDT
bob = 0.5 BTC
}
Proofs are external (JSON)
The .sph file never contains signatures or addresses. Signatures are provided in a separate JSON file after compilation:
{
"swap_id": "a3f8c2d1e4b7...",
"signatures": {
"alice": { "address": "bc1qalice...", "signature": "H7f8c2..." },
"bob": { "address": "bc1qbob...", "signature": "K9d3e1..." }
}
}
Sign the swap_id using your Bitcoin wallet. Then call verify_proof.
compiled = compile_source(open("trade.sph").read())
result = verify_proof(compiled, proof_json)
assert result["status"] == "signatures_valid"
Proof output
{
"swap_id": "a3f8c2...",
"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" }
},
"before": { "alice": "0.5 BTC", "bob": "50000 USDT" },
"after": { "alice": "50000 USDT", "bob": "0.5 BTC" },
"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" }
]
}
}
Why it is safe
- Non-custodial by construction
- No on-chain execution
- Conservation per asset
- Delta per participant
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.6.tar.gz.
File metadata
- Download URL: sophi-0.2.6.tar.gz
- Upload date:
- Size: 19.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f4c8e7f5f23dba2c000d02570b499b29c5f4106923930d0e86b90ffde816d6a
|
|
| MD5 |
7f89ce04b226ac8f93845a2d7bcd4f6f
|
|
| BLAKE2b-256 |
9585c49a34f8df53020370d2e1e5a263af251dc54c8a60816b7aa13d1cb50950
|
File details
Details for the file sophi-0.2.6-py3-none-any.whl.
File metadata
- Download URL: sophi-0.2.6-py3-none-any.whl
- Upload date:
- Size: 20.9 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 |
b7135a21cf36ab2213eb09ac8c187e972da3cbcac408630f33ba033ea5855322
|
|
| MD5 |
3393bae2416af77df6d8eacfefb63188
|
|
| BLAKE2b-256 |
b5f2974a85853d45521c8e1bd0b27e9f9a3b701b86a20fcaf12161ff873088e0
|