Added an option to sign bytes as well as UTF-8 strings (#7923)

This commit is contained in:
Matt Hauff 2021-08-04 09:27:44 -07:00 committed by GitHub
parent deac3ad3cc
commit b66bd13295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -101,10 +101,18 @@ def generate_and_print_cmd():
required=True,
)
@click.option("--hd_path", "-t", help="Enter the HD path in the form 'm/12381/8444/n/n'", type=str, required=True)
def sign_cmd(message: str, fingerprint: int, hd_path: str):
@click.option(
"--as-bytes",
"-b",
help="Sign the message as sequence of bytes rather than UTF-8 string",
default=False,
show_default=True,
is_flag=True,
)
def sign_cmd(message: str, fingerprint: int, hd_path: str, as_bytes: bool):
from .keys_funcs import sign
sign(message, fingerprint, hd_path)
sign(message, fingerprint, hd_path, as_bytes)
@keys_cmd.command("verify", short_help="Verify a signature with a pk")

View File

@ -105,7 +105,7 @@ def delete(fingerprint: int):
keychain.delete_key_by_fingerprint(fingerprint)
def sign(message: str, fingerprint: int, hd_path: str):
def sign(message: str, fingerprint: int, hd_path: str, as_bytes: bool):
k = Keychain()
private_keys = k.get_all_private_keys()
@ -114,8 +114,9 @@ def sign(message: str, fingerprint: int, hd_path: str):
if sk.get_g1().get_fingerprint() == fingerprint:
for c in path:
sk = AugSchemeMPL.derive_child_sk(sk, c)
data = bytes.fromhex(message) if as_bytes else bytes(message, "utf-8")
print("Public key:", sk.get_g1())
print("Signature:", AugSchemeMPL.sign(sk, bytes(message, "utf-8")))
print("Signature:", AugSchemeMPL.sign(sk, data))
return None
print(f"Fingerprint {fingerprint} not found in keychain")