Package: btclib
A Python library for 'bitcoin cryptography'ProjectPackageSupported platformsFormatting standardsCoding standardsType checkingDocumentationCI/CDConversationsBrowse GitHub Code Repositorybtclibis a
Python3type annotatedlibrary intended for teaching, learning, and using bitcoin;
the focus is on elliptic curve cryptography and bitcoin's blockchain.It is rigorously and extensively tested: the test suitecovers 100%of the code base and reproduces results from both informal
and major reference sources.Originally developed for theBitcoin and Blockchain Technologycourse at the University of Milano-Bicocca,
btclib is not intended for production environments:
it is often refactored for improved clarity,
without care for backward compatibility; moreover,
some of its algorithms could be broken using side-channel attacks.The library is not limited to the bitcon elliptic curve secp256k1;
anyway, FFI bindings tolibsecp256k1(the optimized C library used by Bitcoin Core)
are available for this curve and used by default.Included features are:modulo algebra functions (gcd, inverse, legendre symbol, square root)octets / integer / point / var_int / var_bytes helper functionselliptic curve classfast algebra implemented using Jacobian coordinatesdouble scalar multiplication (Straus's algorithm, also known as
Shamir's trick)multi scalar multiplication (Bos-coster's algorithm)point simmetry solution: odd/even, low/high, and quadratic residueelliptic curves: SEC 1 v1 and v2, NIST, Brainpool, and
low cardinality test curvesECDSA signature with (transaction) DER encodingECDSA signature with (message) compact encoding: standard p2pkh andBIP137/Electrumextensions to p2wpkh and p2wpkh-p2shRFC 6979for deterministic signature
schemesEC Schnorr signature (according toBIP340bitcoin standardization)batch validationthreshold signature (see test-suite)MuSig multi-signature (see test-suite)Borromean ring signatureSign-to-contract commitmentDiffie-HellmanPedersen committmentBase58 encoding/decodingp2pkh/p2sh addresses and WIFsBech32 encoding/decodingp2wpkh/p2wsh native SegWit addresses and their legacy p2sh-wrapped versionsBIP32hierarchical deterministic key chainsSLIP132key versions (xprv, yprv, zprv, Yprv, Zprv, tprv, uprv, vprv, and Uprv)
with corresponding mapping to
p2pkh/p2sh, p2wpkh-p2sh, p2wpkh, p2wsh-p2sh, p2wsh and p2tr addressesBIP39wordlists and mnemonic for generating deterministic keysElectrumstandard for mnemonicScript encoding/decodingnulldata, p2pk, p2ms, p2pkh, p2sh, p2wpkh, p2wsh and p2tr ScriptPubKeysBlockHeader and Block data classesOutPoint, TxIn, TxOut, and TX data classeslegacy, segwit_v0 and taproot transaction hash signaturesBIP174partially signed bitcoin transactions (PSBT):
PsbtIn, PbstOut, and Psbt data classesTo install (and/or upgrade) btclib:python-mpipinstall--upgradebtclibYou might want to install btclib into a
python virtual environment; e.g. from the root folder:Shell:python-mvenvvenv_btclibsource./venv_btclib/bin/activate
python-mpipinstall--upgradebtclibWindows CMD or PowerShell:python-mvenvvenv_btclib.\venv_btclib\Scripts\activatepython-mpipinstall--upgradebtclibWindows Git bash shell:python-mvenvvenv_btclibcd./venv_btclib/Scripts
.activatecd../..
python-mpipinstall--upgradebtclibSeeCONTRIBUTINGif you are interested
in btclib develoment.SeeSECURITYif you have found a security vulnerability.