-
-
Notifications
You must be signed in to change notification settings - Fork 2
Remove ecdsa dependency, use cryptography only II #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e0e3707
9e554bb
713ec1d
90dbb3d
d4e387d
1086429
0b8fb05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| import os | ||
|
|
||
| import ecdsa | ||
| import pytest | ||
|
|
||
| from slip10 import HARDENED_INDEX, SLIP10, InvalidInputError, PrivateDerivationError | ||
| from slip10.utils import SECP256K1 | ||
|
|
||
| SEED_1 = "000102030405060708090a0b0c0d0e0f" | ||
| SEED_2 = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" | ||
|
|
@@ -440,10 +440,9 @@ def test_sanity_checks(): | |
| == slip10.get_xpriv_from_path([]) | ||
| ) | ||
| non_extended_pubkey = slip10.get_privkey_from_path("m") | ||
| pubkey = ecdsa.SigningKey.from_string( | ||
| non_extended_pubkey, ecdsa.SECP256k1 | ||
| ).get_verifying_key() | ||
| assert pubkey.to_string("compressed") == slip10.get_pubkey_from_path("m") | ||
| assert SECP256K1.privkey_to_pubkey( | ||
| non_extended_pubkey | ||
| ) == slip10.get_pubkey_from_path("m") | ||
| # But getting from "m'" does not make sense | ||
| with pytest.raises(ValueError, match="invalid format"): | ||
| slip10.get_pubkey_from_path("m'") | ||
|
|
@@ -914,3 +913,22 @@ def test_slip10_vectors(): | |
| assert node.chaincode.hex() == chaincode | ||
| assert node.privkey.hex() == privkey | ||
| assert node.pubkey.hex() == pubkey | ||
|
|
||
|
|
||
| def test_secp256r1_derivation_retry(): | ||
| # Test retry in public key to public key derivation | ||
| # https://github.com/satoshilabs/slips/blob/master/slip-0010.md#test-derivation-retry-for-nist256p1 | ||
| chaincode, pubkey = SLIP10.from_seed( | ||
| bytes.fromhex(SEED_1), curve_name="secp256r1" | ||
| ).get_extended_pubkey_from_path("m/28578'") | ||
| chaincode, pubkey = SLIP10( | ||
| chaincode, pubkey=pubkey, curve_name="secp256r1" | ||
| ).get_extended_pubkey_from_path("m/33941") | ||
| assert ( | ||
| chaincode.hex() | ||
| == "9e87fe95031f14736774cd82f25fd885065cb7c358c1edf813c72af535e83071" | ||
| ) | ||
| assert ( | ||
| pubkey.hex() | ||
| == "0235bfee614c0d5b2cae260000bb1d0d84b270099ad790022c1ae0b2e782efe120" | ||
| ) | ||
|
Comment on lines
+918
to
+934
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, although ideally we should have a test that takes the |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import pytest | ||
|
|
||
| from slip10.utils import SECP256K1, SECP256R1 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("curve", (SECP256K1, SECP256R1)) | ||
| def test_curve_arithmetic(curve): | ||
| generator = curve.multiply_generator(1) | ||
| minus_generator = curve.multiply_generator(curve.order - 1) | ||
| double_generator = curve.multiply_generator(2) | ||
| triple_generator = curve.multiply_generator(3) | ||
|
|
||
| assert curve.add_points(curve.point_at_infinity, generator) == generator | ||
| assert curve.add_points(generator, curve.point_at_infinity) == generator | ||
| assert curve.add_points(generator, minus_generator) == curve.point_at_infinity | ||
| assert curve.add_points(generator, generator) == double_generator | ||
| assert curve.add_points(generator, double_generator) == triple_generator | ||
|
|
||
| assert curve.multiply_generator(0) == curve.point_at_infinity | ||
| assert curve.multiply_generator(curve.order) == curve.point_at_infinity | ||
| assert curve.multiply_generator(curve.order + 1) == generator |
Uh oh!
There was an error while loading. Please reload this page.