Zeth - Zerocash on Ethereum
0.8
Reference implementation of the Zeth protocol by Clearmatics
|
◆ digest_to_binary_string()
str zeth.core.utils.digest_to_binary_string |
( |
bytes |
digest | ) |
|
Definition at line 168 of file utils.py.
169 return "".join([
"{0:08b}".format(b)
for b
in digest])
◆ encode_abi()
bytes zeth.core.utils.encode_abi |
( |
List[str] |
type_names, |
|
|
List[Any] |
data |
|
) |
| |
Typed wrapper around eth_abi.encode_abi
Definition at line 97 of file utils.py.
97 def encode_abi(type_names: List[str], data: List[Any]) -> bytes:
99 Typed wrapper around eth_abi.encode_abi
101 return eth_abi.encode_abi(type_names, data)
◆ encode_single()
bytes zeth.core.utils.encode_single |
( |
str |
type_name, |
|
|
Any |
data |
|
) |
| |
Typed wrapper around eth_abi.encode_single
Definition at line 90 of file utils.py.
92 Typed wrapper around eth_abi.encode_single
94 return eth_abi.encode_single(type_name, data)
◆ eth_address_from_private_key()
str zeth.core.utils.eth_address_from_private_key |
( |
bytes |
eth_private_key | ) |
|
Definition at line 129 of file utils.py.
130 pk = eth_keys.keys.PrivateKey(eth_private_key)
131 return pk.public_key.to_address()
◆ eth_address_to_bytes()
bytes zeth.core.utils.eth_address_to_bytes |
( |
str |
eth_addr | ) |
|
Binary encoding of ethereum address to 20 bytes
Definition at line 104 of file utils.py.
106 Binary encoding of ethereum address to 20 bytes
109 assert len(eth_addr) == 42
110 assert eth_addr.startswith(
"0x")
111 return bytes.fromhex(eth_addr[2:])
◆ eth_address_to_bytes32()
bytes zeth.core.utils.eth_address_to_bytes32 |
( |
str |
eth_addr | ) |
|
Binary encoding of ethereum address to 32 bytes
Definition at line 114 of file utils.py.
116 Binary encoding of ethereum address to 32 bytes
◆ eth_uint256_to_int()
int zeth.core.utils.eth_uint256_to_int |
( |
str |
eth_uint256 | ) |
|
Definition at line 121 of file utils.py.
122 assert isinstance(eth_uint256, str)
123 assert eth_uint256.startswith(
"0x")
124 return int.from_bytes(
◆ extend_32bytes()
bytes zeth.core.utils.extend_32bytes |
( |
bytes |
value | ) |
|
Pad value on the left with zeros, to make 32 bytes.
Definition at line 202 of file utils.py.
204 Pad value on the left with zeros, to make 32 bytes.
206 assert len(value) <= 32
207 return bytes(32-len(value)) + value
◆ from_zeth_units()
EtherValue zeth.core.utils.from_zeth_units |
( |
int |
zeth_units | ) |
|
Convert a quantity of ether / token to Zeth units
Definition at line 227 of file utils.py.
229 Convert a quantity of ether / token to Zeth units
231 return EtherValue(zeth_units * constants.ZETH_PUBLIC_UNIT_VALUE,
"wei")
◆ get_contracts_dir()
str zeth.core.utils.get_contracts_dir |
( |
| ) |
|
Definition at line 255 of file utils.py.
256 return os.environ.get(
257 'ZETH_CONTRACTS_DIR',
◆ get_zeth_dir()
str zeth.core.utils.get_zeth_dir |
( |
| ) |
|
Definition at line 249 of file utils.py.
250 return os.environ.get(
252 normpath(join(dirname(__file__),
"..",
"..",
"..")))
◆ hex_digest_to_binary_string()
str zeth.core.utils.hex_digest_to_binary_string |
( |
str |
digest | ) |
|
Definition at line 162 of file utils.py.
163 if len(digest) % 2 == 1:
164 digest =
"0" + digest
165 return "".join([
"{0:04b}".format(
int(c, 16))
for c
in digest])
◆ hex_extend_32bytes()
str zeth.core.utils.hex_extend_32bytes |
( |
str |
element | ) |
|
Extend a hex string to represent 32 bytes
Definition at line 210 of file utils.py.
212 Extend a hex string to represent 32 bytes
215 if len(res) % 2 != 0:
◆ hex_list_to_uint256_list()
List[int] zeth.core.utils.hex_list_to_uint256_list |
( |
Sequence[Union[str, List[str]]] |
elements | ) |
|
Given an array of hex strings, return an array of int values by converting
each hex string to evm uint256 words, and flattening the final list.
Definition at line 189 of file utils.py.
190 elements: Sequence[Union[str, List[str]]]) -> List[int]:
192 Given an array of hex strings, return an array of int values by converting
193 each hex string to evm uint256 words, and flattening the final list.
◆ hex_to_uint256_list()
Iterable[int] zeth.core.utils.hex_to_uint256_list |
( |
str |
hex_str | ) |
|
Given a hex string of arbitrary size, split into uint256 ints, left padding
with 0s.
Definition at line 172 of file utils.py.
174 Given a hex string of arbitrary size, split into uint256 ints, left padding
177 if hex_str.startswith(
"0x"):
178 hex_str = hex_str[2:]
179 assert len(hex_str) % 2 == 0
181 next_idx = len(hex_str) -
int((len(hex_str) - 1) / 64) * 64
182 while next_idx <= len(hex_str):
183 sub_str = hex_str[start_idx:next_idx]
184 yield int(sub_str, 16)
186 next_idx = next_idx + 64
◆ int64_to_bytes()
bytes zeth.core.utils.int64_to_bytes |
( |
int |
number | ) |
|
Definition at line 154 of file utils.py.
155 return number.to_bytes(8,
'big')
◆ int64_to_hex()
str zeth.core.utils.int64_to_hex |
( |
int |
number | ) |
|
◆ int_and_bytelen_from_hex()
Tuple[int, int] zeth.core.utils.int_and_bytelen_from_hex |
( |
str |
value_hex | ) |
|
Decode prefixed / non-prefixed hex string and extract the length in bytes
as well as the value.
Definition at line 134 of file utils.py.
136 Decode prefixed / non-prefixed hex string and extract the length in bytes
137 as well as the value.
139 assert len(value_hex) % 2 == 0
140 if value_hex.startswith(
"0x"):
141 num_bytes =
int((len(value_hex) - 2) / 2)
143 num_bytes =
int(len(value_hex) / 2)
144 return (
int(value_hex, 16), num_bytes)
◆ int_to_hex()
str zeth.core.utils.int_to_hex |
( |
int |
value, |
|
|
int |
num_bytes |
|
) |
| |
Create prefixed hex string enforcing a specific byte-length.
Definition at line 147 of file utils.py.
147 def int_to_hex(value: int, num_bytes: int) -> str:
149 Create prefixed hex string enforcing a specific byte-length.
151 return "0x" + value.to_bytes(num_bytes, byteorder=
'big').hex()
◆ message_to_bytes()
bytes zeth.core.utils.message_to_bytes |
( |
Any |
message_list | ) |
|
Encode a list of variables, or list of lists of variables into a byte
vector
Definition at line 277 of file utils.py.
280 Encode a list of variables, or list of lists of variables into a byte
286 data_bytes = bytearray()
292 if isinstance(m, int):
293 m_hex =
"{0:0>4X}".format(m)
294 elif isinstance(m, str)
and (m[1] ==
"x"):
◆ open_web3()
Any zeth.core.utils.open_web3 |
( |
str |
url, |
|
|
Optional[str] |
certificate = None , |
|
|
bool |
insecure = False |
|
) |
| |
Create a Web3 context from an http URL.
Definition at line 28 of file utils.py.
30 certificate: Optional[str] =
None,
31 insecure: bool =
False) -> Any:
33 Create a Web3 context from an http URL.
35 if certificate
and not exists(certificate):
36 raise FileNotFoundError(f
"certificate file not found: {certificate}")
37 assert not certificate
or exists(certificate)
38 request_verify: Union[str, bool,
None] =
False if insecure
else certificate
40 'timeout': WEB3_HTTP_PROVIDER_TIMEOUT_SEC,
41 'verify': request_verify,
43 return Web3(HTTPProvider(url, request_kwargs=request_kwargs))
◆ parse_zksnark_arg()
str zeth.core.utils.parse_zksnark_arg |
( |
| ) |
|
Parse the zksnark argument and return its value
Definition at line 234 of file utils.py.
236 Parse the zksnark argument and return its value
238 parser = argparse.ArgumentParser(
239 description=
"Testing Zeth transactions using the specified zkSNARK " +
240 "('GROTH16' or 'PGHR13').\nNote that the zkSNARK must match the one " +
241 "used on the prover server.")
242 parser.add_argument(
"zksnark", help=
"Set the zkSNARK to use")
243 args = parser.parse_args()
244 if args.zksnark
not in constants.VALID_ZKSNARKS:
245 return sys.exit(errors.SNARK_NOT_SUPPORTED)
◆ short_commitment()
str zeth.core.utils.short_commitment |
( |
bytes |
cm | ) |
|
Summary of the commitment value, in some standard format.
Definition at line 306 of file utils.py.
308 Summary of the commitment value, in some standard format.
◆ string_list_flatten()
List[str] zeth.core.utils.string_list_flatten |
( |
Sequence[Union[str, List[str]]] |
str_list | ) |
|
Flatten a list containing strings or lists of strings.
Definition at line 261 of file utils.py.
263 Flatten a list containing strings or lists of strings.
265 if any(isinstance(el, (list, tuple))
for el
in str_list):
268 if isinstance(el, (list, tuple)):
271 strs.append(cast(str, el))
274 return cast(List[str], str_list)
◆ to_zeth_units()
int zeth.core.utils.to_zeth_units |
( |
EtherValue |
value | ) |
|
Convert a quantity of ether / token to Zeth units
Definition at line 220 of file utils.py.
222 Convert a quantity of ether / token to Zeth units
224 return int(value.wei / constants.ZETH_PUBLIC_UNIT_VALUE)
◆ WEB3_HTTP_PROVIDER_TIMEOUT_SEC
int zeth.core.utils.WEB3_HTTP_PROVIDER_TIMEOUT_SEC = 60 |
List[int] hex_list_to_uint256_list(Sequence[Union[str, List[str]]] elements)
str hex_extend_32bytes(str element)
int eth_uint256_to_int(str eth_uint256)
bytes int64_to_bytes(int number)
Any open_web3(str url, Optional[str] certificate=None, bool insecure=False)
List[str] string_list_flatten(Sequence[Union[str, List[str]]] str_list)
str int_to_hex(int value, int num_bytes)
Tuple[int, int] int_and_bytelen_from_hex(str value_hex)
bytes encode_single(str type_name, Any data)
bytes encode_abi(List[str] type_names, List[Any] data)
bytes eth_address_to_bytes(str eth_addr)
bytes extend_32bytes(bytes value)
bytes eth_address_to_bytes32(str eth_addr)
str digest_to_binary_string(bytes digest)
str short_commitment(bytes cm)
int to_zeth_units(EtherValue value)
EtherValue from_zeth_units(int zeth_units)
bytes message_to_bytes(Any message_list)
str hex_digest_to_binary_string(str digest)
str int64_to_hex(int number)
Iterable[int] hex_to_uint256_list(str hex_str)
str eth_address_from_private_key(bytes eth_private_key)