Skip to content

Commit

Permalink
Add batch sign (#30)
Browse files Browse the repository at this point in the history
* Add batch sign

* Fix eth2.0-deposit-cli checksum

* Fix formatting

* Fix flake8
  • Loading branch information
tsudmi authored Apr 24, 2023
1 parent 41b8f6f commit bbaf1dc
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions cli/sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@


@click.command()
@click.option(
"--payloads-file",
required=False,
help="The path to the file containing signing payloads. Defaults to ./payloads.json",
default="./payloads.json",
type=click.Path(exists=True, file_okay=True, dir_okay=False),
)
@click.option(
"--output-file",
required=False,
help="The file to save signatures to. Defaults to ./output.json.",
default="./output.json",
type=click.Path(exists=False, file_okay=True, dir_okay=False),
)
@click.option(
"--horcrux-file",
prompt="Enter the path to the horcrux keystore",
Expand All @@ -22,7 +36,9 @@
for your password as otherwise it will appear in your shell history.)""",
prompt="Enter the horcrux password used during your horcrux creation",
)
def sign(horcrux_file: str, horcrux_password: str) -> None:
def sign(
payloads_file: str, output_file: str, horcrux_file: str, horcrux_password: str
) -> None:
"""Unlocks the keystore and signs the data."""
horcrux_file = horcrux_file.strip()
if not os.path.exists(horcrux_file):
Expand All @@ -32,17 +48,23 @@ def sign(horcrux_file: str, horcrux_password: str) -> None:
with open(horcrux_file, "r") as key_file:
keystore = HorcruxPbkdf2Keystore.create_from_json(json.load(key_file))

signing_data = click.prompt(
text="Enter hexadecimal encoded data to sign", type=click.STRING
).strip()
if signing_data.startswith("0x"):
signing_data = signing_data[2:]
click.echo(f"Loading payloads from {payloads_file}...")
with open(payloads_file, "r") as f:
payloads = json.load(f)

# decrypt and sign data
private_key = int.from_bytes(keystore.decrypt(horcrux_password), "big")
signature = bls_pop.Sign(private_key, bytes.fromhex(signing_data))

click.echo(f"Signature: {click.style(f'0x{signature.hex()}', fg='green')}")
click.echo("Signing payloads...")
signatures = {}
for index, payload in payloads.items():
signature = bls_pop.Sign(private_key, bytes.fromhex(payload))
signatures[index] = signature.hex()

with open(output_file, "w") as f:
json.dump(signatures, f)

click.echo(f"Signatures saved to {click.style(output_file, fg='green')}...")
click.echo(f"Horcrux index: {click.style(f'{keystore.index}', fg='green')}")
click.echo(
f"""Next steps:
Expand Down

0 comments on commit bbaf1dc

Please sign in to comment.