Zeth - Zerocash on Ethereum
0.8
Reference implementation of the Zeth protocol by Clearmatics
|
|
NetworkConfig | get_eth_network (Optional[str] eth_network) |
|
Any | open_web3_from_network (NetworkConfig eth_net) |
|
str | load_contract_address (str contract_addr) |
|
Any | open_web3_from_ctx (ClientConfig ctx) |
|
Dict[str, Any] | get_erc20_abi () |
|
InstanceDescription | get_erc20_instance_description (str token_address) |
|
None | write_mixer_description (str mixer_desc_file, MixerDescription mixer_desc) |
|
MixerDescription | load_mixer_description (str mixer_desc_file) |
|
MixerDescription | load_mixer_description_from_ctx (ClientConfig ctx) |
|
str | get_zeth_address_file (ClientConfig ctx) |
|
ZethAddressPub | load_zeth_address_public (ClientConfig ctx) |
|
None | write_zeth_address_public (ZethAddressPub pub_addr, str pub_addr_file) |
|
ZethAddressPriv | load_zeth_address_secret (ClientConfig ctx) |
|
None | write_zeth_address_secret (ZethAddressPriv secret_addr, str addr_file) |
|
ZethAddress | load_zeth_address (ClientConfig ctx) |
|
Wallet | open_wallet (Any mixer_instance, ZethAddressPriv js_secret, ClientConfig ctx) |
|
int | do_sync (Any web3, Wallet wallet, PairingParameters pp, Optional[str] wait_tx, Optional[Callable[[ZethNoteDescription], None]] callback=None, Optional[int] batch_size=None) |
|
str | pub_address_file (str addr_file) |
|
str | find_pub_address_file (str base_file) |
|
ProverClient | create_prover_client (ClientConfig ctx) |
|
MixerClient | create_mixer_client (ClientConfig ctx, Optional[ProverClient] prover_client=None) |
|
Tuple[MixerClient, MixerDescription] | create_mixer_client_and_mixer_desc (ClientConfig ctx, Optional[ProverClient] prover_client=None) |
|
str | zeth_note_short (ZethNoteDescription note_desc) |
|
None | zeth_note_short_print (ZethNoteDescription note_desc) |
|
Tuple[ZethAddressPub, EtherValue] | parse_output (str output_str) |
|
str | load_eth_address (Optional[str] eth_addr) |
|
None | write_eth_address (str eth_addr, str eth_addr_file) |
|
Optional[bytes] | load_eth_private_key (Optional[str] private_key_file) |
|
None | write_eth_private_key (bytes private_key, str private_key_file) |
|
◆ create_mixer_client()
Create a MixerClient for an existing deployment.
Definition at line 381 of file utils.py.
383 prover_client: Optional[ProverClient] =
None) -> MixerClient:
385 Create a MixerClient for an existing deployment.
◆ create_mixer_client_and_mixer_desc()
Create a MixerClient and MixerDescription object, for an existing deployment.
Definition at line 391 of file utils.py.
393 prover_client: Optional[ProverClient] =
None
394 ) -> Tuple[MixerClient, MixerDescription]:
396 Create a MixerClient and MixerDescription object, for an existing deployment.
400 mixer_instance = mixer_desc.mixer.instantiate(web3)
401 if prover_client
is None:
403 prover_config = prover_client.get_configuration()
404 mixer_client = MixerClient(web3, prover_config, mixer_instance)
405 return (mixer_client, mixer_desc)
◆ create_prover_client()
Create a prover client using the settings from the commands context.
Definition at line 373 of file utils.py.
375 Create a prover client using the settings from the commands context.
378 ctx.prover_server_endpoint, ctx.prover_config_file)
◆ do_sync()
Implementation of sync, reused by several commands. Returns the
block_number synced to. Also updates and saves the MerkleTree.
Definition at line 289 of file utils.py.
292 pp: PairingParameters,
293 wait_tx: Optional[str],
294 callback: Optional[Callable[[ZethNoteDescription],
None]] =
None,
295 batch_size: Optional[int] =
None) -> int:
297 Implementation of sync, reused by several commands. Returns the
298 block_number synced to. Also updates and saves the MerkleTree.
300 def _do_sync() -> int:
301 wallet_next_block = wallet.get_next_block()
304 if chain_block_number >= wallet_next_block:
305 new_merkle_root: Optional[bytes] =
None
307 print(f
"SYNCHING blocks ({wallet_next_block} - {chain_block_number})")
308 mixer_instance = wallet.mixer_instance
315 new_merkle_root = mix_result.new_merkle_root
316 for note_desc
in wallet.receive_notes(
317 mix_result.output_events, pp):
321 spent_commits = wallet.mark_nullifiers_used(mix_result.nullifiers)
322 for commit
in spent_commits:
323 print(f
" SPENT: {commit}")
325 wallet.update_and_save_state(next_block=chain_block_number + 1)
329 our_merkle_root = wallet.merkle_tree.get_root()
330 assert new_merkle_root == our_merkle_root
332 return chain_block_number
340 tx_receipt = web3.eth.waitForTransactionReceipt(wait_tx, 10000)
341 tx = web3.eth.getTransaction(wait_tx)
342 gas_used = tx_receipt.gasUsed
343 status = tx_receipt.status
344 size_bytes = len(tx.input)
346 f
"{wait_tx[0:8]}: gasUsed={gas_used}, status={status}, "
347 f
"input_size={size_bytes}")
◆ find_pub_address_file()
str zeth.cli.utils.find_pub_address_file |
( |
str |
base_file | ) |
|
Given a file name, which could point to a private or public key file, guess
at the name of the public key file.
Definition at line 359 of file utils.py.
361 Given a file name, which could point to a private or public key file, guess
362 at the name of the public key file.
365 if exists(pub_addr_file):
367 if exists(base_file):
370 raise ClickException(f
"No public key file {pub_addr_file} or {base_file}")
◆ get_erc20_abi()
Dict[str, Any] zeth.cli.utils.get_erc20_abi |
( |
| ) |
|
Definition at line 187 of file utils.py.
189 openzeppelin_dir = join(
190 zeth_dir,
"zeth_contracts",
"node_modules",
"openzeppelin-solidity")
192 openzeppelin_dir,
"contracts",
"token",
"ERC20",
"IERC20.sol")
194 erc20_interface = compiled_sol[ierc20_path +
":IERC20"]
195 return erc20_interface[
"abi"]
◆ get_erc20_instance_description()
◆ get_eth_network()
NetworkConfig zeth.cli.utils.get_eth_network |
( |
Optional[str] |
eth_network | ) |
|
Parse the `eth_network` parameter to extract a URL. If `eth_network` does
not contain a URL, try interpreting it as a network name, otherwise
interpret it as a file to load the network config from. Fall back to a
default network config filename, and finally the default network name.
Definition at line 84 of file utils.py.
86 Parse the `eth_network` parameter to extract a URL. If `eth_network` does
87 not contain a URL, try interpreting it as a network name, otherwise
88 interpret it as a file to load the network config from. Fall back to a
89 default network config filename, and finally the default network name.
91 if eth_network
is None:
92 if exists(ETH_NETWORK_FILE_DEFAULT):
93 eth_network = ETH_NETWORK_FILE_DEFAULT
95 eth_network = ETH_NETWORK_DEFAULT
97 if eth_network.startswith(
"http"):
99 return NetworkConfig(ETH_NETWORK_DEFAULT, eth_network)
102 if exists(eth_network):
103 with open(eth_network)
as network_f:
104 return NetworkConfig.from_json(network_f.read())
108 endpoint = ETH_RPC_ENDPOINT_DEFAULTS[eth_network]
109 return NetworkConfig(eth_network, endpoint)
110 except KeyError
as ex:
111 raise ClickException(f
"invalid network name / url: {eth_network}")
from ex
◆ get_zeth_address_file()
str zeth.cli.utils.get_zeth_address_file |
( |
ClientConfig |
ctx | ) |
|
Definition at line 224 of file utils.py.
225 return ctx.address_file
◆ load_contract_address()
str zeth.cli.utils.load_contract_address |
( |
str |
contract_addr | ) |
|
Parse a string as either an eth address, or a contract instance file.
Definition at line 121 of file utils.py.
123 Parse a string as either an eth address, or a contract instance file.
125 if contract_addr.startswith(
"0x"):
126 return Web3.toChecksumAddress(contract_addr)
127 if exists(contract_addr):
128 with open(contract_addr,
"r")
as instance_f:
129 instance = InstanceDescription.from_json_dict(json.load(instance_f))
130 return Web3.toChecksumAddress(instance.address)
131 raise ClickException(
132 f
"failed to parse as address or instance file: {contract_addr}")
◆ load_eth_address()
str zeth.cli.utils.load_eth_address |
( |
Optional[str] |
eth_addr | ) |
|
Given an --eth-addr command line param, either parse the address, load from
the file, or use a default file name.
Definition at line 444 of file utils.py.
446 Given an --eth-addr command line param, either parse the address, load from
447 the file, or use a default file name.
449 eth_addr = eth_addr
or ETH_ADDRESS_DEFAULT
450 if eth_addr.startswith(
"0x"):
451 return Web3.toChecksumAddress(eth_addr)
453 with open(eth_addr,
"r")
as eth_addr_f:
454 return Web3.toChecksumAddress(eth_addr_f.read().rstrip())
455 raise ClickException(f
"could find file or parse eth address: {eth_addr}")
◆ load_eth_private_key()
Optional[bytes] zeth.cli.utils.load_eth_private_key |
( |
Optional[str] |
private_key_file | ) |
|
Definition at line 465 of file utils.py.
466 private_key_file = private_key_file
or ETH_PRIVATE_KEY_FILE_DEFAULT
467 if exists(private_key_file):
468 with open(private_key_file,
"rb")
as private_key_f:
469 return private_key_f.read(32)
◆ load_mixer_description()
Return mixer and token (if present) contract instances
Definition at line 212 of file utils.py.
214 Return mixer and token (if present) contract instances
216 with open(mixer_desc_file,
"r")
as desc_f:
217 return MixerDescription.from_json_dict(json.load(desc_f))
◆ load_mixer_description_from_ctx()
◆ load_zeth_address()
Load a ZethAddress secret from a file, and the associated public address,
and return as a ZethAddress.
Definition at line 265 of file utils.py.
267 Load a ZethAddress secret from a file, and the associated public address,
268 and return as a ZethAddress.
270 return ZethAddress.from_secret_public(
◆ load_zeth_address_public()
Load a ZethAddressPub from a key file.
Definition at line 228 of file utils.py.
230 Load a ZethAddressPub from a key file.
234 with open(pub_addr_file,
"r")
as pub_addr_f:
235 return ZethAddressPub.parse(pub_addr_f.read())
◆ load_zeth_address_secret()
Read ZethAddressPriv
Definition at line 247 of file utils.py.
252 with open(addr_file,
"r")
as addr_f:
253 return ZethAddressPriv.from_json(addr_f.read())
◆ open_wallet()
Load a wallet using a secret key.
Definition at line 275 of file utils.py.
277 js_secret: ZethAddressPriv,
278 ctx: ClientConfig) -> Wallet:
280 Load a wallet using a secret key.
282 wallet_dir = ctx.wallet_dir
286 mixer_instance, WALLET_USERNAME, wallet_dir, js_secret, tree_hash)
◆ open_web3_from_ctx()
◆ open_web3_from_network()
Any zeth.cli.utils.open_web3_from_network |
( |
NetworkConfig |
eth_net | ) |
|
Definition at line 114 of file utils.py.
116 url=eth_net.endpoint,
117 certificate=eth_net.certificate,
118 insecure=eth_net.insecure)
◆ parse_output()
Parse a string of the form "<receiver_pub_address>,<value>" to an output
specification. <receiver_pub_address> can be a file name containing the
address. "<value>" is interpreted as the <default-address-file>,<value>.
Definition at line 421 of file utils.py.
421 def parse_output(output_str: str) -> Tuple[ZethAddressPub, EtherValue]:
423 Parse a string of the form "<receiver_pub_address>,<value>" to an output
424 specification. <receiver_pub_address> can be a file name containing the
425 address. "<value>" is interpreted as the <default-address-file>,<value>.
427 parts = output_str.split(
",")
429 addr = ZETH_PUBLIC_ADDRESS_FILE_DEFAULT
431 elif len(parts) == 2:
435 raise ClickException(f
"invalid output spec: {output_str}")
438 with open(addr,
"r")
as addr_f:
441 return (ZethAddressPub.parse(addr), EtherValue(value))
◆ pub_address_file()
str zeth.cli.utils.pub_address_file |
( |
str |
addr_file | ) |
|
The name of a public address file, given the secret address file.
Definition at line 352 of file utils.py.
354 The name of a public address file, given the secret address file.
356 return splitext(addr_file)[0] +
".pub"
◆ write_eth_address()
None zeth.cli.utils.write_eth_address |
( |
str |
eth_addr, |
|
|
str |
eth_addr_file |
|
) |
| |
Definition at line 458 of file utils.py.
459 if exists(eth_addr_file):
460 raise ClickException(f
"refusing to overwrite address \"{eth_addr_file}\"")
461 with open(eth_addr_file,
"w")
as eth_addr_f:
462 eth_addr_f.write(eth_addr)
◆ write_eth_private_key()
None zeth.cli.utils.write_eth_private_key |
( |
bytes |
private_key, |
|
|
str |
private_key_file |
|
) |
| |
Definition at line 473 of file utils.py.
474 if exists(private_key_file):
475 raise ClickException(
476 f
"refusing to overwrite private key \"{private_key_file}\"")
477 with open(private_key_file,
"wb")
as private_key_f:
478 private_key_f.write(private_key)
◆ write_mixer_description()
None zeth.cli.utils.write_mixer_description |
( |
str |
mixer_desc_file, |
|
|
MixerDescription |
mixer_desc |
|
) |
| |
Write the mixer (and token) instance information
Definition at line 202 of file utils.py.
203 mixer_desc_file: str,
204 mixer_desc: MixerDescription) ->
None:
206 Write the mixer (and token) instance information
208 with open(mixer_desc_file,
"w")
as instance_f:
209 json.dump(mixer_desc.to_json_dict(), instance_f)
◆ write_zeth_address_public()
None zeth.cli.utils.write_zeth_address_public |
( |
ZethAddressPub |
pub_addr, |
|
|
str |
pub_addr_file |
|
) |
| |
Write a ZethAddressPub to a file
Definition at line 238 of file utils.py.
239 pub_addr: ZethAddressPub, pub_addr_file: str) ->
None:
241 Write a ZethAddressPub to a file
243 with open(pub_addr_file,
"w")
as pub_addr_f:
244 pub_addr_f.write(
str(pub_addr))
◆ write_zeth_address_secret()
None zeth.cli.utils.write_zeth_address_secret |
( |
ZethAddressPriv |
secret_addr, |
|
|
str |
addr_file |
|
) |
| |
Write ZethAddressPriv to file
Definition at line 256 of file utils.py.
257 secret_addr: ZethAddressPriv, addr_file: str) ->
None:
259 Write ZethAddressPriv to file
261 with open(addr_file,
"w")
as addr_f:
262 addr_f.write(secret_addr.to_json())
◆ zeth_note_short()
Generate a short human-readable description of a commitment.
Definition at line 408 of file utils.py.
410 Generate a short human-readable description of a commitment.
414 return f
"{cm}: value={value} ETH, addr={note_desc.address}"
◆ zeth_note_short_print()
Definition at line 417 of file utils.py.
418 print(f
" NEW NOTE: {zeth_note_short(note_desc)}")
NetworkConfig get_eth_network(Optional[str] eth_network)
None write_eth_address(str eth_addr, str eth_addr_file)
Any open_web3_from_ctx(ClientConfig ctx)
ProverClient create_prover_client(ClientConfig ctx)
None write_zeth_address_public(ZethAddressPub pub_addr, str pub_addr_file)
str load_contract_address(str contract_addr)
Wallet open_wallet(Any mixer_instance, ZethAddressPriv js_secret, ClientConfig ctx)
Any open_web3(str url, Optional[str] certificate=None, bool insecure=False)
str load_eth_address(Optional[str] eth_addr)
str find_pub_address_file(str base_file)
MixerDescription load_mixer_description_from_ctx(ClientConfig ctx)
Tuple[MixerClient, MixerDescription] create_mixer_client_and_mixer_desc(ClientConfig ctx, Optional[ProverClient] prover_client=None)
ZethAddressPriv load_zeth_address_secret(ClientConfig ctx)
Tuple[ZethAddressPub, EtherValue] parse_output(str output_str)
ITreeHash get_tree_hash_for_pairing(str pairing_name)
ZethAddress load_zeth_address(ClientConfig ctx)
None zeth_note_short_print(ZethNoteDescription note_desc)
str zeth_note_short(ZethNoteDescription note_desc)
Any compile_files(List[str] files, **Any kwargs)
str get_zeth_address_file(ClientConfig ctx)
None write_eth_private_key(bytes private_key, str private_key_file)
Optional[bytes] load_eth_private_key(Optional[str] private_key_file)
None write_mixer_description(str mixer_desc_file, MixerDescription mixer_desc)
str short_commitment(bytes cm)
MixerDescription load_mixer_description(str mixer_desc_file)
Any open_web3_from_network(NetworkConfig eth_net)
EtherValue from_zeth_units(int zeth_units)
int get_block_number(Any web3)
None write_zeth_address_secret(ZethAddressPriv secret_addr, str addr_file)
str pub_address_file(str addr_file)
ZethAddressPub load_zeth_address_public(ClientConfig ctx)
int do_sync(Any web3, Wallet wallet, PairingParameters pp, Optional[str] wait_tx, Optional[Callable[[ZethNoteDescription], None]] callback=None, Optional[int] batch_size=None)
InstanceDescription get_erc20_instance_description(str token_address)
Iterator[MixResult] get_mix_results(Any web3, Any mixer_instance, int start_block, int end_block, Optional[int] batch_size=None)
MixerClient create_mixer_client(ClientConfig ctx, Optional[ProverClient] prover_client=None)
Dict[str, Any] get_erc20_abi()