Skip to main content

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


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.2.5.tar.gz (19.2 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.2.5-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sophi-0.2.5.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

Hashes for sophi-0.2.5.tar.gz
Algorithm Hash digest
SHA256 2f4dae34083fe40b2b9353c7521589db4b6ee0ed5547aff009472eea51e476e8
MD5 c759b5405b9978ecc5fe7cb10dc2db0f
BLAKE2b-256 660f1b573de403558409a5313407f887e5ee3f213754069a44648261ac6f3204

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sophi-0.2.5-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

Hashes for sophi-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9abf3553a9f5117ce243ec613835987c8512137d87f636ff60148b72feaf4a27
MD5 4971c3df5f12669769c3563eb5196ab1
BLAKE2b-256 5e735dbe07f2bb4f7bd13c74881b0f8e0aca0af1b68527c791c27bfc5832ee2b

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