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.4.tar.gz (13.8 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.4-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sophi-0.1.4.tar.gz
  • Upload date:
  • Size: 13.8 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.4.tar.gz
Algorithm Hash digest
SHA256 8030d914a37ccbdac5a0df0efa3f89e287c01eade728ad79fc9d8e56287c6767
MD5 06397046ea70717fc0d50726e8fcf46e
BLAKE2b-256 643cc0bb95a236cbcf7f8cf2f958f0807513192188081c6501028fdb686583c1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sophi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 14.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 fe984b6e5c4d4e911671bae69e948e8cb1ac3681fee6dcda01d395d78bdd251c
MD5 e2c9317cdd587ef3a34847aaa1f9cc64
BLAKE2b-256 0fceb2dcf73ea8076c870954e2abd7710d78ceabd063c954cfde3bc28ca61e9e

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