Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
public_key_operations.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 # Copyright (c) 2015-2022 Clearmatics Technologies Ltd
4 #
5 # SPDX-License-Identifier: LGPL-3.0+
6 
7 """
8 Functions for processing public keys, common to multiple commands.
9 """
10 
11 from coordinator.crypto import \
12  SigningKey, get_verification_key, \
13  export_verification_key, \
14  create_key_evidence, export_signature
15 from typing import Optional
16 from os.path import exists
17 
18 
20  key: SigningKey,
21  public_key_file: Optional[str],
22  evidence_file: Optional[str]) -> None:
23  """
24  Print (and optionally save) public information about a private key.
25  """
26 
27  if public_key_file and exists(public_key_file):
28  raise Exception("public key file already exists")
29  if evidence_file and exists(evidence_file):
30  raise Exception("evidence file already exists")
31 
32  pub_key = get_verification_key(key)
33  key_evidence = create_key_evidence(key)
34  pub_key_str = export_verification_key(pub_key)
35  evidence_str = export_signature(key_evidence)
36 
37  if public_key_file:
38  with open(public_key_file, "w") as pk_f:
39  pk_f.write(pub_key_str)
40  if evidence_file:
41  with open(evidence_file, "w") as ev_f:
42  ev_f.write(evidence_str)
43 
44  print("Public Verification Key:")
45  print(pub_key_str)
46  print("\nKey Evidence:")
47  print(evidence_str)
coordinator.crypto
Definition: crypto.py:1
coordinator.crypto.export_signature
str export_signature(bytes sig)
Definition: crypto.py:74
coordinator.crypto.export_verification_key
str export_verification_key(ecdsa.VerifyingKey vk)
Definition: crypto.py:66
zeth.cli.zeth_get_verification_key.get_verification_key
None get_verification_key(Context ctx, Optional[str] vk_out)
Definition: zeth_get_verification_key.py:15
commands.public_key_operations.public_key_information
None public_key_information(SigningKey key, Optional[str] public_key_file, Optional[str] evidence_file)
Definition: public_key_operations.py:19
coordinator.crypto.create_key_evidence
Signature create_key_evidence(ecdsa.SigningKey key)
Definition: crypto.py:103