Skip to content

Commit

Permalink
moved tests in their own folder
Browse files Browse the repository at this point in the history
  • Loading branch information
fametrano committed Jun 23, 2018
1 parent 308eff5 commit 63177a8
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 79 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,4 @@ ENV/
# vscode
.vscode/

.DS_Store
File renamed without changes.
Empty file added btclib/__init__.py
Empty file.
File renamed without changes.
6 changes: 3 additions & 3 deletions scripts/bip32.py → btclib/bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from hmac import HMAC
from hashlib import sha512
from base58 import b58encode_check, b58decode_check
from ellipticcurves import secp256k1 as ec
from wifaddress import h160, address_from_pubkey
from btclib.base58 import b58encode_check, b58decode_check
from btclib.ellipticcurves import secp256k1 as ec
from btclib.wifaddress import h160, address_from_pubkey

# VERSION BYTES = 4 bytes Base58 encode starts with
MAINNET_PRIVATE = b'\x04\x88\xAD\xE4' # xprv
Expand Down
6 changes: 3 additions & 3 deletions scripts/bip39.py → btclib/bip39.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""BIP39 entropy / mnemonic / seed functions"""

from hashlib import sha256, sha512
from pbkdf2 import PBKDF2
from mnemonic import mnemonic_dict
from bip32 import PRIVATE, bip32_master_prvkey_from_seed
from btclib.pbkdf2 import PBKDF2
from btclib.mnemonic import mnemonic_dict
from btclib.bip32 import PRIVATE, bip32_master_prvkey_from_seed

def bip39_raw_entropy_checksum(raw_entr):
# raw_entr 256-bit checksum
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions scripts/ecdsa.py → btclib/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from typing import Tuple
from hashlib import sha256
from ellipticcurves import secp256k1 as ec
from numbertheory import mod_inv
from rfc6979 import rfc6979
from ecsignutils import int_from_hash
from wifaddress import int_from_prvkey
from btclib.ellipticcurves import secp256k1 as ec
from btclib.numbertheory import mod_inv
from btclib.rfc6979 import rfc6979
from btclib.ecsignutils import int_from_hash
from btclib.wifaddress import int_from_prvkey


def ecdsa_sign(m, prv, eph_prv = None, hasher = sha256) -> Tuple[int, int]:
Expand Down
15 changes: 6 additions & 9 deletions scripts/ecsigntocontract.py → btclib/ecsigntocontract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@
"""

from hashlib import sha256
from base58 import b58decode_check, base58digits as b58digits
from ellipticcurves import secp256k1 as ec
from numbertheory import mod_inv, mod_sqrt
from string import hexdigits
from rfc6979 import rfc6979
from ecsignutils import int_from_hash
from wifaddress import int_from_prvkey
from ecdsa import ecdsa_sign, ecdsa_verify, check_dsasig, ecdsa_sign_raw
from ecssa import ecssa_sign, ecssa_verify, check_ssasig, ecssa_sign_raw
from btclib.ellipticcurves import secp256k1 as ec
from btclib.rfc6979 import rfc6979
from btclib.ecsignutils import int_from_hash
from btclib.wifaddress import int_from_prvkey
from btclib.ecdsa import ecdsa_sign, ecdsa_verify, check_dsasig, ecdsa_sign_raw
from btclib.ecssa import ecssa_sign, ecssa_verify, check_ssasig, ecssa_sign_raw


def tweak(k, c, hasher=sha256):
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions scripts/ecssa.py → btclib/ecssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from typing import Tuple
from hashlib import sha256
from ellipticcurves import secp256k1 as ec
from numbertheory import mod_inv
from rfc6979 import rfc6979
from ecsignutils import int_from_hash
from wifaddress import int_from_prvkey
from btclib.ellipticcurves import mod_inv, secp256k1 as ec
from btclib.rfc6979 import rfc6979
from btclib.ecsignutils import int_from_hash
from btclib.wifaddress import int_from_prvkey

# %% ecssa sign
# https://github.com/sipa/secp256k1/blob/968e2f415a5e764d159ee03e95815ea11460854e/src/modules/schnorr/schnorr.md
Expand Down
7 changes: 4 additions & 3 deletions scripts/electrum_seed.py → btclib/electrum_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"""electrum entropy / mnemonic / seed functions"""

from hashlib import sha512
from pbkdf2 import PBKDF2
import hmac
from bip32 import PRIVATE, bip32_master_prvkey_from_seed, bip32_ckd, bip32_xpub_from_xprv
from mnemonic import mnemonic_dict
from btclib.pbkdf2 import PBKDF2
from btclib.mnemonic import mnemonic_dict
from btclib.bip32 import PRIVATE, bip32_master_prvkey_from_seed, \
bip32_ckd, bip32_xpub_from_xprv

MNEMONIC_VERSIONS = {'standard' : '01',
'segwit' : '100',
Expand Down
2 changes: 1 addition & 1 deletion scripts/ellipticcurves.py → btclib/ellipticcurves.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from math import sqrt
from typing import Tuple, NewType, Union, Optional
from numbertheory import mod_inv, mod_sqrt
from btclib.numbertheory import mod_inv, mod_sqrt

# (x, y) Point tuple with (None, None) being the infinity point
PointTuple = NewType('PointTuple', Tuple[Optional[int], Optional[int]])
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions scripts/rfc6979.py → btclib/rfc6979.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"""

from hashlib import sha256
from ellipticcurves import secp256k1 as ec
from struct import pack
from binascii import hexlify
from hmac import new as hmac_new
import hmac
from btclib.ellipticcurves import secp256k1 as ec

default_hasher = sha256
default_hash_digest_size = 32
Expand Down Expand Up @@ -57,19 +57,19 @@ def rfc6979_raw(prv, m, hasher=default_hasher):
prv_and_m = int2octets(prv) + bits2octets(m)
v = b'\x01' * hash_size
k = b'\x00' * hash_size
k = hmac_new(k, v + b'\x00' + prv_and_m, hasher).digest()
v = hmac_new(k, v, hasher).digest()
k = hmac_new(k, v + b'\x01' + prv_and_m, hasher).digest()
v = hmac_new(k, v, hasher).digest()
k = hmac.new(k, v + b'\x00' + prv_and_m, hasher).digest()
v = hmac.new(k, v, hasher).digest()
k = hmac.new(k, v + b'\x01' + prv_and_m, hasher).digest()
v = hmac.new(k, v, hasher).digest()
while True:
t = b''
while len(t) * 8 < qlen:
v = hmac_new(k, v, hasher).digest()
v = hmac.new(k, v, hasher).digest()
t = t + v
nonce = bits2int(t)
if nonce >= 1 and nonce < ec.order:
# here it should be checked that nonce do not yields a invalid signature
# but then I should put the signature generation here
return nonce
k = hmac_new(k, v + b'\x00', hasher).digest()
v = hmac_new(k, v, hasher).digest()
k = hmac.new(k, v + b'\x00', hasher).digest()
v = hmac.new(k, v, hasher).digest()
4 changes: 2 additions & 2 deletions scripts/wifaddress.py → btclib/wifaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
and public keys (addresses)
'''

from ellipticcurves import secp256k1 as ec
from base58 import b58encode_check, b58decode_check, base58digits
from hashlib import sha256, new as hnew
from btclib.ellipticcurves import secp256k1 as ec
from btclib.base58 import b58encode_check, b58decode_check, base58digits


def bytes_from_prvkey(prv):
Expand Down
6 changes: 3 additions & 3 deletions scripts/bip32_testvector1.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3

from ellipticcurves import secp256k1 as ec
from wifaddress import h160, address_from_pubkey
from hmac import HMAC
from hashlib import sha512
from base58 import b58encode_check, b58decode_check
from btclib.ellipticcurves import secp256k1 as ec
from btclib.wifaddress import h160, address_from_pubkey
from btclib.base58 import b58encode_check, b58decode_check

## https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki

Expand Down
Empty file added tests/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion scripts/test_base58.py → tests/test_base58.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from base58 import b58encode, b58encode_check, b58decode, b58decode_check
from btclib.base58 import b58encode, b58encode_check, b58decode, b58decode_check

class TestBase58CheckEncoding(unittest.TestCase):
def test_b58_encode_decode(self):
Expand Down
16 changes: 8 additions & 8 deletions scripts/test_bip32.py → tests/test_bip32.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import os
import json

from bip32 import PRIVATE, \
bip32_master_prvkey_from_seed, \
bip32_xpub_from_xprv, \
bip32_ckd, \
bip32_derive, \
bip32_crack, \
bip32_child_index, \
address_from_xpub
from btclib.bip32 import PRIVATE, \
bip32_master_prvkey_from_seed, \
bip32_xpub_from_xprv, \
bip32_ckd, \
bip32_derive, \
bip32_crack, \
bip32_child_index, \
address_from_xpub

class TestBIP32(unittest.TestCase):
def test_bip32_vector1(self):
Expand Down
10 changes: 5 additions & 5 deletions scripts/test_bip39.py → tests/test_bip39.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import os
import json
import math
from bip39 import PRIVATE, \
bip39_mnemonic_from_raw_entropy, \
bip39_raw_entropy_from_mnemonic, \
bip39_master_prvkey_from_mnemonic, \
bip39_seed_from_mnemonic
from btclib.bip39 import PRIVATE, \
bip39_mnemonic_from_raw_entropy, \
bip39_raw_entropy_from_mnemonic, \
bip39_master_prvkey_from_mnemonic, \
bip39_seed_from_mnemonic

class TestBIP39Wallet(unittest.TestCase):
def test_bip39_wallet(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_der.py → tests/test_der.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from der import encode_DER_sig, check_DER_sig
from btclib.der import encode_DER_sig, check_DER_sig

class TestDER(unittest.TestCase):
def test_der(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_ecdsa.py → tests/test_ecdsa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from ecdsa import ec, ecdsa_sign, ecdsa_verify, ecdsa_pubkey_recovery
from btclib.ecdsa import ec, ecdsa_sign, ecdsa_verify, ecdsa_pubkey_recovery

class TestEcdsa(unittest.TestCase):
def test_ecdsa(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3

import unittest
from ecsigntocontract import ec, sha256, \
ecdsa_verify, ecssa_verify, \
ecdsa_commit_and_sign, ecssa_commit_and_sign, \
verify_commit
from btclib.ecsigntocontract import ec, sha256, \
ecdsa_verify, ecssa_verify, \
ecdsa_commit_and_sign, ecssa_commit_and_sign, \
verify_commit

class TestSignToContract(unittest.TestCase):
def test_digntocontract(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_ecssa.py → tests/test_ecssa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from ecssa import ec, ecssa_sign, ecssa_verify, ecssa_pubkey_recovery
from btclib.ecssa import ec, ecssa_sign, ecssa_verify, ecssa_pubkey_recovery

class TestEcssa(unittest.TestCase):
def test_ecssa(self):
Expand Down
4 changes: 2 additions & 2 deletions scripts/test_ecssamusig.py → tests/test_ecssamusig.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"""

import unittest
from ecssa import sha256, int_from_prvkey, ec, int_from_hash, ecssa_verify
from btclib.ecssa import sha256, int_from_prvkey, ec, int_from_hash, \
ecssa_verify

class TestEcssaMuSig(unittest.TestCase):
def test_ecssamusig(self):
msg = 'message to sign'
print(msg)
m = sha256(msg.encode()).digest()

# first signer (is the message needed here? maybe for rfc6979?)
Expand Down
10 changes: 5 additions & 5 deletions scripts/test_electrum_seed.py → tests/test_electrum_seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import unittest
import os
import json
from electrum_seed import PRIVATE, \
bip32_xpub_from_xprv, \
electrum_entropy_from_mnemonic, \
electrum_mnemonic_from_raw_entropy, \
electrum_master_prvkey_from_mnemonic
from btclib.electrum_seed import PRIVATE, \
bip32_xpub_from_xprv, \
electrum_entropy_from_mnemonic, \
electrum_mnemonic_from_raw_entropy, \
electrum_master_prvkey_from_mnemonic

class TestMnemonicDictionaries(unittest.TestCase):
def test_electrum_wallet(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env python3

import unittest
from ellipticcurves import secp256k1, \
ec11_13, ec79_43, ec263_269, ec263_270, ec263_280
from btclib.ellipticcurves import secp256k1, \
ec11_13, ec79_43, \
ec263_269, ec263_270, ec263_280

class Testsecp256k1(unittest.TestCase):
def test_all_curves(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_mnemonic.py → tests/test_mnemonic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from mnemonic import mnemonic_dict
from btclib.mnemonic import mnemonic_dict

class TestMnemonicDictionaries(unittest.TestCase):
def test_1(self):
Expand Down
2 changes: 1 addition & 1 deletion scripts/test_rfc6979.py → tests/test_rfc6979.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import unittest
from rfc6979 import sha256, rfc6979
from btclib.rfc6979 import sha256, rfc6979

class Testrfc6979(unittest.TestCase):
def test_rfc6979(self):
Expand Down
8 changes: 4 additions & 4 deletions scripts/test_wifaddress.py → tests/test_wifaddress.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3

import unittest
from wifaddress import ec, \
wif_from_prvkey, prvkey_from_wif, \
address_from_pubkey, hash160_from_address, \
pubkey_from_prvkey, bytes_from_prvkey
from btclib.wifaddress import ec, \
wif_from_prvkey, prvkey_from_wif, \
address_from_pubkey, hash160_from_address, \
pubkey_from_prvkey, bytes_from_prvkey

class TestKeys(unittest.TestCase):

Expand Down

0 comments on commit 63177a8

Please sign in to comment.