Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/btclib-org/btclib into mo…
Browse files Browse the repository at this point in the history
…ntgomery-ladder
  • Loading branch information
fametrano committed Nov 1, 2020
2 parents b373fa7 + d717e51 commit 184edde
Show file tree
Hide file tree
Showing 46 changed files with 1,541 additions and 856 deletions.
6 changes: 5 additions & 1 deletion HISTORY.md
Expand Up @@ -8,7 +8,11 @@ full year, short month, short day (YYYY-M-D)

Major changes includes:

- nothing so far
- introduced HdKeypaths, PartialSigs, PsbtIn, PsbtOut,
and Psbt data classes and their associated helper functions
- refactored Diffie-Hellman and ANSI-X9.63-KDF
- introduced dataclasses_json as requirement, used to
serialize to file json representation of dataclasses

## v2020.8.21

Expand Down
44 changes: 35 additions & 9 deletions README.md
Expand Up @@ -34,19 +34,45 @@ some of its algorithms could be broken using side-channel attacks.
[![GitHub License](https://img.shields.io/github/license/btclib-org/btclib.svg)](https://github.com/btclib-org/btclib/blob/master/LICENSE)
[![Follow on Twitter](https://img.shields.io/twitter/follow/btclib?style=social&logo=twitter)](https://twitter.com/intent/follow?screen_name=btclib)

btclib does not have external requirements or dependencies;
to install (and/or upgrade) it:
To install (and/or upgrade) btclib and its requirements:

```shell
pip install --upgrade btclib
```
pip install --upgrade -r requirements.txt
pip install --upgrade btclib

Some dev tools are required to develop and test btclib;
You might want to install btclib and its requirements into a
python virtual environment; e.g. from the root folder:

Bash shell

python -m venv venv
source venv/bin/activate
pip install --upgrade -r requirements.txt
pip install --upgrade btclib

Windows CMD or PowerShell:

python -m venv venv
.\venv\Scripts\activate
pip install --upgrade -r requirements.txt
pip install --upgrade btclib

Windows Git bash shell:

python -m venv venv
cd ./venv/Scripts
. activate
cd ../..
pip install --upgrade -r requirements.txt
pip install --upgrade btclib

Some development tools are required to develop and test btclib;
they can be installed with:

```shell
pip install --upgrade -r requirements-dev.txt
```
pip install --upgrade -r requirements-dev.txt

Developers might also consider to install btclib in editable way:

pip install --upgrade -e ./

* * *

Expand Down
1 change: 0 additions & 1 deletion TODO.md
Expand Up @@ -15,7 +15,6 @@
- add wallet infrastructure
- add sign(address, msg) using wallet infrastrucure
- isinstance(entr, bytearray) or isinstance(entr, bytes)
- revise ansi_x963_kdf
- optimizations:
- https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication
- https://cryptojedi.org/peter/data/eccss-20130911b.pdf
Expand Down
53 changes: 10 additions & 43 deletions btclib/alias.py
Expand Up @@ -14,7 +14,7 @@
"""

from io import BytesIO
from typing import Any, Callable, Iterable, List, Tuple, TypedDict, Union
from typing import Any, Callable, List, Tuple, Union

# binary octets are eight-bit bytes or hex-string (not text string)
#
Expand Down Expand Up @@ -89,45 +89,6 @@
Entropy = Union[BinStr, int, bytes]


# BIP 32 derivation path
# absolute path as "m/44h/0'/1H/0/10" string
# relative path as "./0/10" string
# relative path as sequence of integer indexes
# relative one level child derivation with single 4-bytes index
# relative one level child derivation with single integer index
# TODO: allow also Iterable[bytes], while making mypy happy
Path = Union[str, Iterable[int], int, bytes]


# BIP 32 extended key as a TypedDict
class BIP32KeyDict(TypedDict):
version: bytes
depth: int
parent_fingerprint: bytes
index: bytes
chain_code: bytes
key: bytes


BIP32Key = Union[BIP32KeyDict, String]

# private key inputs:
# integer as Union[int, Octets]
# BIP32key as BIP32Key
# WIF as String
#
# BIP32key and WIF also provide extra info about
# network and (un)compressed-pubkey-derivation
PrvKey = Union[int, bytes, str, BIP32KeyDict]

# public key inputs:
# elliptic curve point as Union[Octets, BIP32Key, Point]
PubKey = Union[bytes, str, BIP32KeyDict, Point]

# public or private key input,
# usable wherever a PubKey is logically expected
Key = Union[int, bytes, str, BIP32KeyDict, Point]

# ECDSA signature
# (r, s)
# both r and s are scalar: 0 < r < ec.n, 0 < s < ec.n
Expand Down Expand Up @@ -157,9 +118,15 @@ class BIP32KeyDict(TypedDict):
# other integers are bytes encoded (require push operation)
# ascii str are for opcodes (e.g. 'OP_HASH160')
# Octets are for data to be pushed
Token = Union[int, str, bytes]
ScriptToken = Union[int, str, bytes]

# Bitcoin script expressed as List[Token]
# Bitcoin script expressed as List[ScriptToken]
# e.g. [OP_HASH160, script_h160, OP_EQUAL]
# or Octets of its byte-encoded representation
Script = Union[Octets, List[Token]]
Script = Union[Octets, List[ScriptToken]]

# A fingerprint is represented as 4 bytes or his string representation
Fingerprint = Union[str, bytes]

# Object that can be textually saved without any conversion
Printable = Union[int, str]
3 changes: 2 additions & 1 deletion btclib/base58address.py
Expand Up @@ -15,7 +15,7 @@

from typing import Optional, Tuple

from .alias import Key, Octets, Script, String
from .alias import Octets, Script, String
from .base58 import b58decode, b58encode
from .hashes import hash160_from_key, hash160_from_script, hash256_from_script
from .network import (
Expand All @@ -25,6 +25,7 @@
network_from_key_value,
)
from .scriptpubkey import scriptPubKey_from_payload
from .to_pubkey import Key
from .utils import bytes_from_octets

# 1. Hash/WitnessProgram from pubkey/scriptPubKey
Expand Down
3 changes: 1 addition & 2 deletions btclib/base58wif.py
Expand Up @@ -10,10 +10,9 @@

from typing import Optional

from .alias import PrvKey
from .base58 import b58encode
from .network import NETWORKS
from .to_pubkey import prvkeyinfo_from_prvkey
from .to_prvkey import PrvKey, prvkeyinfo_from_prvkey


def wif_from_prvkey(
Expand Down
5 changes: 3 additions & 2 deletions btclib/bech32address.py
Expand Up @@ -44,10 +44,11 @@

from typing import Iterable, List, Optional, Tuple

from .alias import Key, Octets, Script, String
from .alias import Octets, Script, String
from .bech32 import b32decode, b32encode
from .hashes import hash160_from_key, hash256_from_script
from .network import NETWORKS, network_from_key_value
from .to_pubkey import Key
from .utils import bytes_from_octets

# 0. bech32 facilities
Expand Down Expand Up @@ -142,7 +143,7 @@ def witness_from_b32address(b32addr: String) -> Tuple[int, bytes, str, bool]:
witprog = _convertbits(data[1:], 5, 8, False)
_check_witness(witvers, bytes(witprog))

is_script_hash = False if witvers == 0 and len(witprog) == 20 else True
is_script_hash = witvers != 0 or len(witprog) != 20
return witvers, bytes(witprog), network, is_script_hash


Expand Down

0 comments on commit 184edde

Please sign in to comment.