diff --git a/genesis-tools/keypair-generator/src/main.rs b/genesis-tools/keypair-generator/src/main.rs index 65f05b39d7d..ee255ed95d8 100644 --- a/genesis-tools/keypair-generator/src/main.rs +++ b/genesis-tools/keypair-generator/src/main.rs @@ -65,6 +65,14 @@ fn main() { println!("SK: {}", key); println!("PK: {}", key.public_key()); println!(); + if generate_config { + let account_id = account_id + .expect("Account id must be specified if --generate-config is used"); + let key_file_name = format!("signer{}_key.json", i); + let mut path = home_dir.to_path_buf(); + path.push(&key_file_name); + generate_key_to_file(account_id, key.clone(), path); + } pks.push(key.public_key()); } diff --git a/scripts/nodelib.py b/scripts/nodelib.py index 617579b769f..f2638c89046 100755 --- a/scripts/nodelib.py +++ b/scripts/nodelib.py @@ -218,8 +218,24 @@ def generate_validator_key(home, is_release, nodocker, image, account_id): subprocess.check_output(['docker', 'run', '-v', '%s:/srv/keypair-generator' % home, '-it', image, 'keypair-generator', '--home=/srv/keypair-generator', '--generate-config', '--account-id=%s' % account_id, 'validator-key']) print("Validator key generated") +def generate_signer_key(home, is_release, nodocker, image, account_id): + print("Generating signer keys...") + if nodocker: + cmd = ['./target/%s/keypair-generator' % ('release' if is_release else 'debug')] + cmd.extend(['--home', home]) + cmd.extend(['--generate-config']) + cmd.extend(['--account-id', account_id]) + cmd.extend(['signer-keys']) + try: + subprocess.call(cmd) + except KeyboardInterrupt: + print("\nStopping NEARCore.") + else: + subprocess.check_output(['docker', 'run', '-v', '%s:/srv/keypair-generator' % home, '-it', image, 'keypair-generator', '--home=/srv/keypair-generator', '--generate-config', '--account-id=%s' % account_id, 'signer-keys']) + print("Signer keys generated") + -def initialize_keys(home, is_release, nodocker, image, account_id): +def initialize_keys(home, is_release, nodocker, image, account_id, generate_signer_keys): if nodocker: install_cargo() compile_package('keypair-generator', is_release) @@ -229,6 +245,8 @@ def initialize_keys(home, is_release, nodocker, image, account_id): except subprocess.CalledProcessError as exc: print("Failed to fetch docker containers: %s" % exc) exit(1) + if generate_signer_keys: + generate_signer_key(home, is_release, nodocker, image, account_id) generate_node_key(home, is_release, nodocker, image) if account_id: generate_validator_key(home, is_release, nodocker, image, account_id) diff --git a/scripts/start_stakewars.py b/scripts/start_stakewars.py index 43ee9488879..8f8e27ed667 100755 --- a/scripts/start_stakewars.py +++ b/scripts/start_stakewars.py @@ -15,6 +15,7 @@ parser.add_argument('--verbose', action='store_true', help='If set, prints verbose logs') parser.add_argument('--home', default=os.path.expanduser('~/.near/'), help='Home path for storing configs, keys and chain data (Default: ~/.near)') parser.add_argument('--init', action='store_true', help='If set, initialize the home dir by generating validator key and node key') + parser.add_argument('--signer-keys', action='store_true', help='If set, generate signer keys for account specified') parser.add_argument('--account-id', default='', help='If set, the account id will be used for running a validator') parser.add_argument( '--image', default='nearprotocol/nearcore:stakewars', @@ -26,7 +27,7 @@ nodocker = args.nodocker or args.local if args.init: - initialize_keys(args.home, not args.debug, nodocker, args.image, args.account_id) + initialize_keys(args.home, not args.debug, nodocker, args.image, args.account_id, args.signer_keys) else: print("****************************************************") print("* Running NEAR validator node for Stake Wars *")