Skip to content

Commit bbaf1dc

Browse files
authored
Add batch sign (#30)
* Add batch sign * Fix eth2.0-deposit-cli checksum * Fix formatting * Fix flake8
1 parent 41b8f6f commit bbaf1dc

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

cli/sign.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88

99

1010
@click.command()
11+
@click.option(
12+
"--payloads-file",
13+
required=False,
14+
help="The path to the file containing signing payloads. Defaults to ./payloads.json",
15+
default="./payloads.json",
16+
type=click.Path(exists=True, file_okay=True, dir_okay=False),
17+
)
18+
@click.option(
19+
"--output-file",
20+
required=False,
21+
help="The file to save signatures to. Defaults to ./output.json.",
22+
default="./output.json",
23+
type=click.Path(exists=False, file_okay=True, dir_okay=False),
24+
)
1125
@click.option(
1226
"--horcrux-file",
1327
prompt="Enter the path to the horcrux keystore",
@@ -22,7 +36,9 @@
2236
for your password as otherwise it will appear in your shell history.)""",
2337
prompt="Enter the horcrux password used during your horcrux creation",
2438
)
25-
def sign(horcrux_file: str, horcrux_password: str) -> None:
39+
def sign(
40+
payloads_file: str, output_file: str, horcrux_file: str, horcrux_password: str
41+
) -> None:
2642
"""Unlocks the keystore and signs the data."""
2743
horcrux_file = horcrux_file.strip()
2844
if not os.path.exists(horcrux_file):
@@ -32,17 +48,23 @@ def sign(horcrux_file: str, horcrux_password: str) -> None:
3248
with open(horcrux_file, "r") as key_file:
3349
keystore = HorcruxPbkdf2Keystore.create_from_json(json.load(key_file))
3450

35-
signing_data = click.prompt(
36-
text="Enter hexadecimal encoded data to sign", type=click.STRING
37-
).strip()
38-
if signing_data.startswith("0x"):
39-
signing_data = signing_data[2:]
51+
click.echo(f"Loading payloads from {payloads_file}...")
52+
with open(payloads_file, "r") as f:
53+
payloads = json.load(f)
4054

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

45-
click.echo(f"Signature: {click.style(f'0x{signature.hex()}', fg='green')}")
58+
click.echo("Signing payloads...")
59+
signatures = {}
60+
for index, payload in payloads.items():
61+
signature = bls_pop.Sign(private_key, bytes.fromhex(payload))
62+
signatures[index] = signature.hex()
63+
64+
with open(output_file, "w") as f:
65+
json.dump(signatures, f)
66+
67+
click.echo(f"Signatures saved to {click.style(output_file, fg='green')}...")
4668
click.echo(f"Horcrux index: {click.style(f'{keystore.index}', fg='green')}")
4769
click.echo(
4870
f"""Next steps:

0 commit comments

Comments
 (0)