Pure Swift Bitcoin Protocol implementation (largely experimental)

Pure Swift Bitcoin Protocol implementation (largely experimental)
From: 'Dr. Craig S. Wrong' via Bitcoin Development Mailing List @ 2024-10-07 12:16 UTC ( / )
  To: Bitcoin Development Mailing List




Hello there!

I wanted to share with y'all a project that I've been working on for more 
than two years called Swift Bitcoin 
(https://github.com/swift-bitcoin/swift-bitcoin 
/ https://swift-bitcoin.github.io)

It started as a way for me to test my own knowledge about the way Bitcoin 
works internally and externally. I first took a stab at implementing the 
various BIPs including with their respective test vectors in my favorite 
language Swift. I then started porting over additional unit tests from the 
Bitcoin Core project which helped me understand a lot of what happens under 
the hood.

While far from complete, today the package offers a comprehensive set of 
idiomatic Swift APIs which covers ECC and Bitcoin cryptography (uses 
libsecp256k1), hash functions, codecs, a full SCRIPT interpreter, 
transaction composition, signature verification, wallet functionality 
(addresses, key derivation, mnemonic, transaction input signing), 
blockchain, mining, RPC and P2P transport (WIP).

About some the advantages of using Swift I can mention the use of actors 
for isolation of mutable state and structured concurrency which guarantees 
data race safety. These are particularly noticeable at the wire protocol 
level where I'm leveraging the SwiftNIO library for non-blocking I/O.

The code does not rely on third party dependencies and produces a very fast 
and small binary which could eventually be suitable for embedded systems 
(coming soon). For Apple platform of course this library fits right in but 
everything is developed and tested on Linux. Also with C / C++ 
interoperability it can also be integrated into any CMake-based project.

Anyway if anyone is interested in knowing more or becoming a contributor 
please reach out to me at toximaxi (at) proton.me. I'm not a protocols guy 
so progress in that area has been slow and I could use some help in that 
particular area as well as many others.

Aside from that let me know what you think. Could an 
experimental/educational project like this one evolve into something useful 
for others?

Thanks everyone for taking the time.

Cheers!

--