Skip to content

Commit

Permalink
INDY-1588: add script to generating bls key proof and update enable_bls
Browse files Browse the repository at this point in the history
Signed-off-by: toktar <[email protected]>
  • Loading branch information
Toktar committed Aug 20, 2018
1 parent bb85fc4 commit 4e5aaa7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
7 changes: 4 additions & 3 deletions scripts/enable_bls
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import argparse
import logging

from plenum.common.config_util import getConfig
from plenum.common.constants import BLS_KEY, ALIAS
from plenum.common.constants import BLS_KEY, ALIAS, BLS_KEY_PROOF
from plenum.common.exceptions import OperationError, NoConsensusYet
from plenum.common.keygen_utils import init_bls_keys
from plenum.common.signer_did import DidSigner
Expand Down Expand Up @@ -58,7 +58,7 @@ def send_node_txn(node_name, bls_key, steward_seed, node_dest):
with Looper() as looper:
looper.add(client)
print('>>>>>>>>>>> Updating NYM with BLS keys...')
data = __prepare_node_data(node_name, bls_key)
data = __prepare_node_data(node_name, *bls_key)
req = __send_node_request(wallet, client,
data,
steward_seed, node_dest)
Expand All @@ -78,10 +78,11 @@ def send_node_txn(node_name, bls_key, steward_seed, node_dest):
print('>>>>>>>>>>>> Generated BLS key {} but failed to add it to the pool'.format(bls_key))


def __prepare_node_data(node_name, bls_key):
def __prepare_node_data(node_name, bls_key, bls_key_proof):
data = {}
data[ALIAS] = node_name
data[BLS_KEY] = bls_key
data[BLS_KEY_PROOF] = bls_key_proof
return data


Expand Down
64 changes: 64 additions & 0 deletions scripts/generate_bls_proof_of_possesion
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#! /usr/bin/env python3
import argparse
import os

from crypto.bls.bls_key_manager import LoadBLSKeyError
from crypto.bls.indy_crypto.bls_crypto_indy_crypto import \
BlsCryptoSignerIndyCrypto
from indy_common.config_helper import NodeConfigHelper
from plenum.bls.bls_key_manager_file import BlsKeyManagerFile
from indy_common.config_util import getConfig

config = getConfig()
config.enableStdOutLogging = False
ENV_FILE_PATH = "/etc/indy/indy.env"


def load_keys() -> (str, str):
node_name = get_node_name()
if node_name is None:
raise LoadBLSKeyError("Please use parameter --name for setting node name.")

node_config_helper = NodeConfigHelper(node_name, getConfig())
keys_dir = os.path.expanduser(node_config_helper.keys_dir)
if not os.path.exists(keys_dir):
raise LoadBLSKeyError("Keys are not exist. Please generate BLS keys.")

dir = os.path.join(keys_dir, node_name)
sk, pk = BlsKeyManagerFile(dir).load_keys()
return sk, pk


def get_node_name():
node_name = parse_args()
node_name_key = 'NODE_NAME'

if os.path.exists(ENV_FILE_PATH):
with open(ENV_FILE_PATH, "r") as fenv:
for line in fenv.readlines():
if line.find(node_name_key) != -1:
node_name = line.split('=')[1].strip()
break
return node_name


def parse_args():
parser = argparse.ArgumentParser(
description="Generate BLS keys proof of possession.")

parser.add_argument('--name', required=False, help='node name')
args = parser.parse_args()
return args.name


if __name__ == "__main__":
pk = sk = None
try:
sk, pk = load_keys()
except LoadBLSKeyError as e:
print(e.args[0])

if None not in [pk, sk]:
print("The Public BLS Key is", pk)
key_proof = BlsCryptoSignerIndyCrypto.generate_key_proof(sk, pk)
print("BLS Proof of possession for the Public BLS Key is", key_proof)

0 comments on commit 4e5aaa7

Please sign in to comment.