Skip to main content

Balance-based non-custodial swap language for Bitcoin

Project description

Sophi

Balance-based non-custodial swap language for Bitcoin.

Sophi is a language with one primitive: the balance. When both sides are equal, a non-custodial atomic swap executes on Bitcoin. No escrow. No intermediary. No custodian.

Install

pip install sophi

Write a swap

swap {
  alice wants  0.5 BTC
  alice gives  50000 USDT

  bob wants    50000 USDT
  bob gives    0.5 BTC
}

Save as trade.sph and run:

sophi compile trade.sph

Blind swap (private values)

swap {
  alice wants  blind(a3f8c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0)
  alice gives  blind(b1e2d3c4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2)

  bob wants    blind(b1e2d3c4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2)
  bob gives    blind(a3f8c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0c2d1e4b7a9f0)
}

Nobody sees the amounts until settlement. This is the foundation of OTC dark pool privacy.

How it works

  • wants — what a party wants to receive
  • gives — what a party is offering
  • blind(hash) — hides the value using SHA-256 commitment
  • partial — accepts partial fill
  • expires block(N) — swap expires at Bitcoin block N

The compiler checks that all balances are in equilibrium before generating anything. If alice gives does not equal bob wants, you get a clear error — not a runtime failure on a live network.

Multi-party

swap {
  alice wants  blind(H1)
  alice gives  blind(H2)

  bob wants    blind(H2)
  bob gives    blind(H3)

  carol wants  blind(H3)
  carol gives  blind(H1)
}

Up to 8 parties. All legs settle atomically.

Non-custodial by construction

Sophi has no syntax for depositing funds into a contract. The only thing you can express is a condition for transfer. Custodial code is not forbidden — it is unwritable.

License

Business Source License 1.1 — converts to Apache 2.0 after 4 years.

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

sophi-0.1.1.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

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

sophi-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file sophi-0.1.1.tar.gz.

File metadata

  • Download URL: sophi-0.1.1.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bcdfdf6f6baa282172b90cf606b0ca37edb260f5426235c0fb74ff4208885b7b
MD5 a86751eec747c8d6f5bf60af7135520a
BLAKE2b-256 bbd6768fa1c7755dc5a188908f8b90ec46739bb8c438049cb12eda7cb2e70034

See more details on using hashes here.

File details

Details for the file sophi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sophi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for sophi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 242a85d416a35f8d2be5f6cdac7f35d74ff95f793867e0858198315a382677dc
MD5 f0a5e5cddc1aab5928fe047c3270a759
BLAKE2b-256 7d16153af3c9c97c533e33697d5db1cff8f0980eabc864e3a47f551c16c9d996

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