-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e8ab5d
commit 45ece77
Showing
13 changed files
with
237 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "thirdparty/bls-signatures"] | ||
path = thirdparty/bls-signatures | ||
url = https://github.com/ArkEcosystem/bls-signatures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,12 @@ | |
## Guide for contributing | ||
|
||
1. Fork the repository on GitHub. | ||
2. Run the tests to confirm they all pass on your system. If they don’t, you’ll need to investigate why they fail. If you’re unable to diagnose this yourself raise it as a bug report. | ||
3. Make your change. | ||
4. Write tests that demonstrate your bug or feature. | ||
5. Run the entire test suite again, confirming that all tests pass including the ones you just added. | ||
6. Send a GitHub Pull Request. GitHub Pull Requests are the expected method of code collaboration on this project. | ||
2. Clone locally (making sure to load submodules): `git clone --recurse-submodules [email protected]:ArkEcosystem/python-crypto.git` | ||
3. Run the tests to confirm they all pass on your system. If they don’t, you’ll need to investigate why they fail. If you’re unable to diagnose this yourself raise it as a bug report. | ||
4. Make your change. | ||
5. Write tests that demonstrate your bug or feature. | ||
6. Run the entire test suite again, confirming that all tests pass including the ones you just added. | ||
7. Send a GitHub Pull Request. GitHub Pull Requests are the expected method of code collaboration on this project. | ||
|
||
If you have any questions, requests or ideas open an issue or ask us in #developers channel on the [ArkEcosystem Discord](https://discord.ark.io/). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from btclib.mnemonic import bip39 | ||
|
||
import sys | ||
import os | ||
from os.path import dirname | ||
|
||
sys.path.append(os.path.join(dirname(dirname(dirname(__file__))), 'thirdparty/bls-signatures/python-impl')) | ||
|
||
from schemes import BasicSchemeMPL | ||
|
||
class BLSPrivateKey(object): | ||
def __init__(self, private_key: bytes): | ||
self.private_key = private_key | ||
|
||
def to_hex(self): | ||
"""Returns a private key in hex format | ||
Returns: | ||
str: private key in hex format | ||
""" | ||
return self.private_key.hex() | ||
|
||
@classmethod | ||
def from_passphrase(cls, passphrase: str): | ||
"""Create PrivateKey object from a given passphrase | ||
Args: | ||
passphrase (str): | ||
Returns: | ||
PrivateKey: Private key object | ||
""" | ||
seed = bip39.seed_from_mnemonic(passphrase, '') | ||
|
||
sk = BasicSchemeMPL.key_gen(seed) | ||
|
||
return cls(bytes(BasicSchemeMPL.derive_child_sk(sk, 0))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import sys | ||
import os | ||
from os.path import dirname | ||
|
||
sys.path.append(os.path.join(dirname(dirname(dirname(__file__))), 'thirdparty/bls-signatures/python-impl')) | ||
|
||
from schemes import PrivateKey | ||
|
||
from crypto.identity.bls_private_key import BLSPrivateKey | ||
|
||
class BLSPublicKey: | ||
def __init__(self, public_key: bytes): | ||
self.public_key = public_key | ||
|
||
def to_hex(self) -> str: | ||
return self.public_key.hex() | ||
|
||
@classmethod | ||
def from_passphrase(cls, passphrase: str): | ||
private_key = BLSPrivateKey.from_passphrase(passphrase) | ||
|
||
return cls(bytes(PrivateKey.from_bytes(private_key.private_key).get_g1())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from crypto.identity.bls_public_key import BLSPrivateKey | ||
|
||
|
||
def test_private_key_from_passphrase(validator): | ||
private_key = BLSPrivateKey.from_passphrase(validator['passphrase']).to_hex() | ||
|
||
assert private_key == validator['bls_private_key'] | ||
|
||
|
||
def test_many_private_keys_from_passphrase(bls_keys): | ||
for bls_private_key in bls_keys: | ||
private_key = BLSPrivateKey.from_passphrase(bls_private_key['passphrase']).to_hex() | ||
|
||
assert private_key == bls_private_key['bls_private_key'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from crypto.identity.bls_public_key import BLSPublicKey | ||
|
||
|
||
def test_public_key_from_passphrase(validator): | ||
public_key = BLSPublicKey.from_passphrase(validator['passphrase']).to_hex() | ||
|
||
assert public_key == validator['bls_public_key'] | ||
|
||
|
||
def test_many_public_keys_from_passphrase(bls_keys): | ||
for bls_public_key in bls_keys: | ||
private_key = BLSPublicKey.from_passphrase(bls_public_key['passphrase']).to_hex() | ||
|
||
assert private_key == bls_public_key['bls_public_key'] |
Submodule bls-signatures
added at
119502