Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
Functions
coordinator.contribute Namespace Reference

Functions

None upload_response (Client client, str response_file, str key_file)
 
None wait_for_turn (Client client, int interval, VerificationKey verification_key)
 
None contribute (str base_url, str key_file, str challenge_file, Callable[[], str] contribute_cb, int wait_interval, Optional[str] server_certificate, bool insecure)
 

Function Documentation

◆ contribute()

None coordinator.contribute.contribute ( str  base_url,
str  key_file,
str  challenge_file,
Callable[[], str]  contribute_cb,
int  wait_interval,
Optional[str]  server_certificate,
bool  insecure 
)
Given a callback that creates a response from a challenge, download a
challenge, create the response via the callback, and sign and upload it.

Definition at line 65 of file contribute.py.

65 def contribute(
66  base_url: str,
67  key_file: str,
68  challenge_file: str,
69  contribute_cb: Callable[[], str],
70  wait_interval: int,
71  server_certificate: Optional[str],
72  insecure: bool) -> None:
73  """
74  Given a callback that creates a response from a challenge, download a
75  challenge, create the response via the callback, and sign and upload it.
76  """
77  # Check key upfront
78  with open(key_file, "rb") as key_f:
79  sk = import_signing_key(key_f.read())
80  print("Got key")
81 
82  client = Client(base_url, server_certificate, insecure)
83 
84  try:
85  if wait_interval:
86  verification_key = get_verification_key(sk)
87  wait_for_turn(client, wait_interval, verification_key)
88 
89  # Get challenge
90  client.get_challenge(challenge_file)
91  print("Got challenge")
92 
93  # Perform the contribution
94  response_file = contribute_cb()
95 
96  except RequestException as err:
97  print(f"EXCEPTION: {err.response.status_code} - {err.response.text}")
98  raise
99 
100  # Sign and upload
101  _upload_response(client, response_file, sk)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ upload_response()

None coordinator.contribute.upload_response ( Client  client,
str  response_file,
str  key_file 
)
Given some response file and a key, sign the response and upload the
coordinator connected to by client.

Definition at line 31 of file contribute.py.

31 def upload_response(client: Client, response_file: str, key_file: str) -> None:
32  """
33  Given some response file and a key, sign the response and upload the
34  coordinator connected to by client.
35  """
36  with open(key_file, "rb") as key_f:
37  sk = import_signing_key(key_f.read())
38  _upload_response(client, response_file, sk)
39 
40 
Here is the call graph for this function:

◆ wait_for_turn()

None coordinator.contribute.wait_for_turn ( Client  client,
int  interval,
VerificationKey  verification_key 
)
Wait until our turn, returning when we can contribute. If anything goes
wrong, an exception is thrown.

Definition at line 41 of file contribute.py.

41 def wait_for_turn(
42  client: Client,
43  interval: int,
44  verification_key: VerificationKey) -> None:
45  """
46  Wait until our turn, returning when we can contribute. If anything goes
47  wrong, an exception is thrown.
48  """
49  contributors = client.get_contributors()
50  our_idx = contributors.get_contributor_index(verification_key)
51  while True:
52  state = client.get_state()
53  current_index = state.next_contributor_index
54  if our_idx is None:
55  raise Exception("contributor is not in the server list")
56  if our_idx < current_index:
57  raise Exception("contributor turn has passed")
58  if our_idx == current_index:
59  return
60  # Wait for interval and try again
61  print(f"Waiting ... (current_idx: {current_index}, our_idx: {our_idx})")
62  time.sleep(interval)
63 
64 
Here is the caller graph for this function:
coordinator.crypto.import_signing_key
ecdsa.SigningKey import_signing_key(bytes sk_b)
Definition: crypto.py:58
coordinator.contribute.upload_response
None upload_response(Client client, str response_file, str key_file)
Definition: contribute.py:31
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
coordinator.contribute.wait_for_turn
None wait_for_turn(Client client, int interval, VerificationKey verification_key)
Definition: contribute.py:41
coordinator.contribute.contribute
None contribute(str base_url, str key_file, str challenge_file, Callable[[], str] contribute_cb, int wait_interval, Optional[str] server_certificate, bool insecure)
Definition: contribute.py:65