Skip to content

Commit c8acd88

Browse files
authored
Improved documentation (#96)
1 parent cfaad37 commit c8acd88

18 files changed

+141
-68
lines changed

.markdownlint.jsonc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
{
2+
3+
// rules https://github.com/DavidAnson/markdownlint
4+
25
// See https://github.com/DavidAnson/markdownlint-cli2 and
36
// https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.jsonc
47

8+
// To locally disable a single error, e.g. MD013:
9+
// <!-- markdownlint-disable MD013 -->
10+
// and after the offending block
11+
// <!-- markdownlint-enable MD013 -->
12+
513
// MD007/ul-indent - Unordered list indentation
614
"MD007": {
715
// Spaces for indent

HISTORY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Notable changes to the codebase are documented here.
44

5-
Release names follow [_calendar versioning_](https://calver.org/):
5+
Release names follow *[calendar versioning](https://calver.org/)*:
66
full year, short month, short day (YYYY-M-D)
77

88
## v2023.1.17
@@ -17,7 +17,7 @@ Major changes include:
1717
- improved typing
1818
- added SECURITY, CONTRIBUTING, bug report and feature request templates
1919
- added pre-commit hooks
20-
- adopted _mypy --strict_ and _from \_\_future\_\_ import annotations_
20+
- adopted *mypy --strict* and *from \_\_future\_\_ import annotations*
2121

2222
## v2022.12.31
2323

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ recursive-include tests *.txt
3535
recursive-exclude docs/build *
3636
recursive-include docs *.bat
3737
recursive-include docs *.py
38+
recursive-include docs *.md
3839
recursive-include docs *.rst
3940
recursive-include docs *.txt
4041
recursive-include docs Makefile

README.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
21
# A Python library for 'bitcoin cryptography'
32

43
<!-- markdownlint-disable MD013 -->
54
| | |
65
| --- | --- |
7-
| Package | [![python](https://img.shields.io/pypi/pyversions/btclib.svg?logo=python)](https://pypi.python.org/pypi/btclib/) [![calver: yyy.m.d](https://img.shields.io/badge/cal_ver-yyyy.m.d-1674b1.svg?logo=calver)](https://calver.org/) [![pypi](https://img.shields.io/pypi/v/btclib.svg?logo=pypi)](https://pypi.python.org/pypi/btclib/) [![downloads](https://static.pepy.tech/badge/btclib)](https://pepy.tech/project/btclib) [![status](https://img.shields.io/pypi/status/btclib.svg)](https://pypi.python.org/pypi/btclib/) [![license](https://img.shields.io/github/license/btclib-org/btclib.svg)](https://github.com/btclib-org/btclib/blob/master/LICENSE) |
6+
| Project | [![status](https://img.shields.io/pypi/status/btclib.svg)](https://pypi.python.org/pypi/btclib/) [![license](https://img.shields.io/github/license/btclib-org/btclib.svg)](https://github.com/btclib-org/btclib/blob/master/LICENSE) |
7+
| Package | [![calver: yyy.m.d](https://img.shields.io/badge/cal_ver-yyyy.m.d-1674b1.svg?logo=calver)](https://calver.org/) [![pypi](https://img.shields.io/pypi/v/btclib.svg?logo=pypi)](https://pypi.python.org/pypi/btclib/) [![downloads](https://static.pepy.tech/badge/btclib)](https://pepy.tech/project/btclib) |
8+
| Supported platforms | [![python](https://img.shields.io/pypi/pyversions/btclib.svg?logo=python)](https://pypi.python.org/pypi/btclib/) |
89
| Formatting standards | [![lint: isort](https://img.shields.io/badge/lint-isort-yellowgreen.svg?logo=isort)](https://github.com/PyCQA/isort) [![lint: black](https://img.shields.io/badge/lint-black-yellowgreen.svg?logo=black)](https://github.com/psf/black) [![lint: flake8](https://img.shields.io/badge/lint-flake8-yellowgreen.svg?logo=flake8)](<https://github.com/PyCQA/flake8>) [![lint: yesqa](https://img.shields.io/badge/lint-yesqa-yellowgreen.svg?logo=yesqa)](<https://github.com/asottile/yesqa>) [![lint: markdownlint-cli2](https://img.shields.io/badge/lint-markdownlint--cli2-yellowgreen.svg?logo=sourcery)](https://github.com/DavidAnson/markdownlint-cli2) |
9-
| Coding standards | [![type check: mypy](https://img.shields.io/badge/type_check-mypy-yellowgreen.svg?logo=mypy)](http://mypy-lang.org/) [![type check: pyright](https://img.shields.io/badge/type_check-pyright-yellowgreen.svg)](https://github.com/microsoft/pyright) [![lint: pylint](https://img.shields.io/badge/lint-pylint-yellowgreen.svg?logo=pylint)](https://github.com/PyCQA/pylint) [![lint: autoflake](https://img.shields.io/badge/lint-autoflake-yellowgreen.svg?logo=autoflake)](https://github.com/PyCQA/autoflake) [![lint: pyupgrade](https://img.shields.io/badge/lint-pyupgrade-yellowgreen.svg?logo=pyupgrade)](https://github.com/asottile/pyupgrade) [![lint: sourcery](https://img.shields.io/badge/lint-sourcery-yellowgreen.svg?logo=sourcery)](https://sourcery.ai) [![security: bandit](https://img.shields.io/badge/security-bandit-yellowgreen.svg?logo=bandit)](https://github.com/PyCQA/bandit) |
10-
| Docs | [![lint: docformatter](https://img.shields.io/badge/lint-docformatter-yellowgreen.svg?logo=docformatter)](https://github.com/PyCQA/docformatter) [![lint: pydocstringformatter](https://img.shields.io/badge/lint-pydocstringformatter-yellowgreen.svg?logo=pydocstringformatter)](https://github.com/DanielNoord/pydocstringformatter) [![lint: pydocstyle](https://img.shields.io/badge/lint-pydocstyle-yellowgreen.svg?logo=pydocstyle)](https://github.com/PyCQA/pydocstyle)|
11-
| CI/CD | [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/btclib-org/btclib/master.svg)](https://results.pre-commit.ci/latest/github/btclib-org/btclib/master) [![lint](https://github.com/btclib-org/btclib/actions/workflows/lint.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/lint.yml) [![test](https://github.com/btclib-org/btclib/actions/workflows/test.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/test.yml) [![test-py312](https://github.com/btclib-org/btclib/actions/workflows/test-pydev.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/test-pydev.yml) [![coverage](https://coveralls.io/repos/github/btclib-org/btclib/badge.svg?logo=coveralls)](https://coveralls.io/github/btclib-org/btclib) [![docs](https://img.shields.io/readthedocs/btclib.svg?logo=readthedocs)](https://btclib.readthedocs.io) |
10+
| Coding standards | [![lint: pylint](https://img.shields.io/badge/lint-pylint-yellowgreen.svg?logo=pylint)](https://github.com/PyCQA/pylint) [![lint: autoflake](https://img.shields.io/badge/lint-autoflake-yellowgreen.svg?logo=autoflake)](https://github.com/PyCQA/autoflake) [![lint: pyupgrade](https://img.shields.io/badge/lint-pyupgrade-yellowgreen.svg?logo=pyupgrade)](https://github.com/asottile/pyupgrade) [![lint: sourcery](https://img.shields.io/badge/lint-sourcery-yellowgreen.svg?logo=sourcery)](https://sourcery.ai) [![security: bandit](https://img.shields.io/badge/security-bandit-yellowgreen.svg?logo=bandit)](https://github.com/PyCQA/bandit) |
11+
| Type checking | [![type check: mypy](https://img.shields.io/badge/type_check-mypy-yellowgreen.svg?logo=mypy)](http://mypy-lang.org/) [![type check: pyright](https://img.shields.io/badge/type_check-pyright-yellowgreen.svg)](https://github.com/microsoft/pyright) |
12+
| Documentation | [![docs](https://readthedocs.org/projects/btclib/badge/?version=latest)](https://btclib.readthedocs.io) [![lint: docformatter](https://img.shields.io/badge/lint-docformatter-yellowgreen.svg?logo=docformatter)](https://github.com/PyCQA/docformatter) [![lint: pydocstringformatter](https://img.shields.io/badge/lint-pydocstringformatter-yellowgreen.svg?logo=pydocstringformatter)](https://github.com/DanielNoord/pydocstringformatter) [![lint: pydocstyle](https://img.shields.io/badge/lint-pydocstyle-yellowgreen.svg?logo=pydocstyle)](https://github.com/PyCQA/pydocstyle)|
13+
| CI/CD | [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) [![pre-commit.ci status](https://results.pre-commit.ci/badge/github/btclib-org/btclib/master.svg)](https://results.pre-commit.ci/latest/github/btclib-org/btclib/master) [![lint](https://github.com/btclib-org/btclib/actions/workflows/lint.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/lint.yml) [![test](https://github.com/btclib-org/btclib/actions/workflows/test.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/test.yml) [![test-py312](https://github.com/btclib-org/btclib/actions/workflows/test-pydev.yml/badge.svg)](https://github.com/btclib-org/btclib/actions/workflows/test-pydev.yml) [![coverage](https://coveralls.io/repos/github/btclib-org/btclib/badge.svg?logo=coveralls)](https://coveralls.io/github/btclib-org/btclib) |
1214
| Conversations | [![slack](https://img.shields.io/badge/slack-btclib_dev-white.svg?logo=slack)](https://bbt-training.slack.com/messages/C01CCJ85AES) [![Follow on Twitter](https://img.shields.io/twitter/follow/btclib?style=social&logo=twitter)](https://twitter.com/intent/follow?screen_name=btclib)|
1315

1416
[Browse GitHub Code Repository](https://github.com/btclib-org/btclib/)
@@ -18,22 +20,28 @@
1820

1921
[btclib](https://btclib.org) is a
2022
Python3 [type annotated](https://docs.python.org/3/library/typing.html)
21-
library intended for teaching, learning, and using bitcoin,
22-
its blockchain, and the associated elliptic curve cryptography.
23+
library intended for teaching, learning, and using bitcoin;
24+
the focus is on elliptic curve cryptography and bitcoin's blockchain.
2325

2426
It is rigorously and extensively tested: the test suite
2527
[covers 100%](https://coveralls.io/github/btclib-org/btclib)
2628
of the code base and reproduces results from both informal
2729
and major reference sources.
2830

2931
Originally developed for the
30-
[_Bitcoin and Blockchain Technology_](https://www.ametrano.net/bbt/)
32+
_[Bitcoin and Blockchain Technology](https://www.ametrano.net/bbt/)_
3133
course at the University of Milano-Bicocca,
3234
btclib is not intended for production environments:
3335
it is often refactored for improved clarity,
3436
without care for backward compatibility; moreover,
3537
some of its algorithms could be broken using side-channel attacks.
3638

39+
The library is not limited to the bitcon elliptic curve secp256k1;
40+
anyway, for this curve FFI bindings to
41+
[libsecp256k1](https://github.com/bitcoin-core/secp256k1)
42+
(the optimized C library used by Bitcoin Core)
43+
are available and used by default.
44+
3745
Included features are:
3846

3947
- modulo algebra functions (gcd, inverse, legendre symbol, square root)
@@ -50,15 +58,15 @@ Included features are:
5058
- ECDSA signature with (message) compact encoding: standard p2pkh and
5159
[BIP137](https://github.com/bitcoin/bips/blob/master/bip-0137.mediawiki)/[Electrum](https://electrum.org/#home)
5260
extensions to p2wpkh and p2wpkh-p2sh
61+
- [RFC 6979](https://tools.ietf.org/html/rfc6979) for deterministic signature
62+
schemes
5363
- EC Schnorr signature (according to
5464
[BIP340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki)
5565
bitcoin standardization)
5666
- batch validation
5767
- threshold signature (see test-suite)
5868
- MuSig multi-signature (see test-suite)
5969
- Borromean ring signature
60-
- [RFC 6979](https://tools.ietf.org/html/rfc6979) to make signature
61-
schemes deterministic
6270
- Sign-to-contract commitment
6371
- Diffie-Hellman
6472
- Pedersen committment
@@ -95,7 +103,7 @@ python -m pip install --upgrade btclib
95103
You might want to install btclib into a
96104
python virtual environment; e.g. from the root folder:
97105

98-
Shell
106+
Shell:
99107

100108
```shell
101109
python -m venv venv_btclib
@@ -105,7 +113,7 @@ python -m pip install --upgrade btclib
105113

106114
Windows CMD or PowerShell:
107115

108-
```cmd
116+
```powershell
109117
python -m venv venv_btclib
110118
.\venv_btclib\Scripts\activate
111119
python -m pip install --upgrade btclib

btclib/amount.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,21 @@
5050

5151

5252
def valid_btc_amount(amount: Any, dust: Decimal = Decimal("0")) -> Decimal:
53-
"""Return the BTC amount as Decimal, if valid and not less than dust."""
53+
"""Return the BTC amount as Decimal, if valid and not less than dust.
54+
55+
Args:
56+
amount (Any): The BTC amount. Assumed to be zero if None.
57+
dust (Decimal, optional): The minum threshould for a valid amount.
58+
Defaults to Decimal("0").
59+
60+
Raises:
61+
BTClibValueError: If the amount is below dust or above max
62+
number of bitcoin ever available.
63+
BTClibValueError: If the amount has too many (>8) decimals.
64+
65+
Returns:
66+
Decimal: The BTC amount converted to Decimal.
67+
"""
5468
# any input that can be converted to str is fine
5569
amount = "0" if amount is None else str(amount)
5670
# using str in the Decimal constructor avoids the

btclib/ec/curve_group_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
- Peter Dettman's field inverses and square roots using a sliding window over blocks of 1s
3838
-https://briansmith.org/ecc-inversion-addition-chains-01
3939
- Joint sparse form (JSF) for double mult
40-
- Interleaving with NAFs
40+
- Interleaving with NAFs
4141
"""
4242

4343
from __future__ import annotations

docs/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Minimal makefile for Sphinx documentation
22
#
33

4-
# You can set these variables from the command line.
5-
SPHINXOPTS =
6-
SPHINXBUILD = sphinx-build
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
78
SOURCEDIR = source
89
BUILDDIR = build
910

docs/README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Move into the btclib project root folder and autogenerate docs:
1919
.. sourcecode:: bash
2020

2121
$ cd /path/to/btclibrootfolder
22-
$ sphinx-apidoc -f -o ./docs/source ./btclib
22+
$ sphinx-apidoc -f -o docs/source btclib/
2323

2424
Perform the above sphinx-apidoc step everytime files are added/removed.
2525

@@ -28,7 +28,7 @@ Then, move into the docs directory and build the docs to see how they look:
2828
.. sourcecode:: bash
2929

3030
$ cd docs
31-
$ make html
31+
$ make clean html
3232

3333
Your ``index.rst`` has been built into ``index.html``
3434
in the output subdirectory (``build/html/index.html``).

docs/make.bat

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ if "%SPHINXBUILD%" == "" (
1010
set SOURCEDIR=source
1111
set BUILDDIR=build
1212

13-
if "%1" == "" goto help
14-
1513
%SPHINXBUILD% >NUL 2>NUL
1614
if errorlevel 9009 (
1715
echo.
@@ -21,15 +19,17 @@ if errorlevel 9009 (
2119
echo.may add the Sphinx directory to PATH.
2220
echo.
2321
echo.If you don't have Sphinx installed, grab it from
24-
echo.http://sphinx-doc.org/
22+
echo.https://www.sphinx-doc.org/
2523
exit /b 1
2624
)
2725

28-
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
2929
goto end
3030

3131
:help
32-
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
3333

3434
:end
3535
popd

docs/requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
m2r2>=0.3.2
2-
Sphinx>=4.3.2
1+
# m2r2
2+
myst-parser
3+
sphinx
4+
sphinx_rtd_theme

0 commit comments

Comments
 (0)