Metadata-Version: 2.4
Name: chaincraft
Version: 1.3.0
Summary: A platform for decentralized protocols — wire, objects, and pedagogical consensus
Author: Chaincraft Contributors
License-Expression: MIT
Project-URL: Homepage, https://github.com/jose-compu/chaincraft-monorepo
Project-URL: Repository, https://github.com/jose-compu/chaincraft-monorepo
Project-URL: Documentation, https://github.com/jose-compu/chaincraft-monorepo#readme
Keywords: blockchain,education,prototyping,distributed,consensus,chaincraft,gossip,p2p
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Education
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: ed25519
Requires-Dist: cryptography>=42.0; extra == "ed25519"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: cryptography>=42.0; extra == "dev"
Dynamic: license-file

# chaincraft

Reference implementation of the Chaincraft wire protocol and object semantics.
Release **[1.3.0](https://pypi.org/project/chaincraft/1.3.0/)** on PyPI.

Open-source toolkit for peer-to-peer protocols like blockchains, chat rooms,
BitTorrent swarms, and content-addressed stores.

## Install

```bash
pip install chaincraft
```

Ed25519 is optional: `pip install "chaincraft[ed25519]"`. The node is
`python3 -m chaincraft.node`. Default listen is `0.0.0.0:9735`.

## Hello World

Two TCP nodes in one process. A listens on `9735`, B on `9736`, B dials A and
gossips `app.hello`.

```python
import time
from chaincraft.mesh import Mesh
from chaincraft.object import SharedObject


class Hello(SharedObject):
    def receive(self, message):
        print("Received:", message["message"])


hello = Hello()
a = Mesh(on_app=lambda t, d: hello.receive(d) if t == "app.hello" else None)
b = Mesh()
print("listening", a.start("127.0.0.1", 9735))
print("listening", b.start("127.0.0.1", 9736))
b.connect(a.listen_addr)
digest = b.broadcast("app.hello", {"message": "Hello, Chaincraft!"})
time.sleep(0.4)
print(digest)
a.close()
b.close()
```

CLI, three languages on one loopback mesh:

```bash
python3 -m chaincraft.node
chaincraft-node 127.0.0.1:9736
chaincraft-ts-node 127.0.0.1:9737
```

Then `{"cmd":"connect","addr":"127.0.0.1:9735"}` on the last two, and
`{"cmd":"send","type":"app.hello","data":{"message":"Hello, Chaincraft!"}}` on
Python.

Further local nodes take unused ports and connect. Remote hosts dial this
machine's unicast IPv4 or DNS name on 9735. `connect` allows loopback,
RFC1918, public unicast IPv4, `localhost`, `.local`, and ordinary DNS names.
Each mesh keeps at most 256 peers.

Specification and the Rust and TypeScript implementations live in the
[monorepo](https://github.com/jose-compu/chaincraft-monorepo).
