Zeth - Zerocash on Ethereum
0.8
Reference implementation of the Zeth protocol by Clearmatics
|
◆ fq_from_bytes()
FQ zeth.core.signing.fq_from_bytes |
( |
bytes |
fq_bytes | ) |
|
Definition at line 205 of file signing.py.
206 return FQ(int.from_bytes(fq_bytes, byteorder=
'big'))
◆ fq_from_hex()
FQ zeth.core.signing.fq_from_hex |
( |
str |
fq_hex | ) |
|
◆ fq_to_bytes()
bytes zeth.core.signing.fq_to_bytes |
( |
FQ |
fq_element | ) |
|
Definition at line 201 of file signing.py.
202 return int(fq_element.n).to_bytes(32, byteorder=
'big')
◆ fq_to_hex()
str zeth.core.signing.fq_to_hex |
( |
FQ |
fq_element | ) |
|
◆ g1_from_json_dict()
G1 zeth.core.signing.g1_from_json_dict |
( |
Dict[str, Any] |
json_dict | ) |
|
◆ g1_to_bytes()
bytes zeth.core.signing.g1_to_bytes |
( |
G1 |
group_el | ) |
|
Encode a group element into a byte string
We assume here the group prime $p$ is written in less than 256 bits
to conform with Ethereum bytes32 type.
Definition at line 217 of file signing.py.
219 Encode a group element into a byte string
220 We assume here the group prime $p$ is written in less than 256 bits
221 to conform with Ethereum bytes32 type.
224 int(group_el[0]).to_bytes(32, byteorder=
'big') + \
225 int(group_el[1]).to_bytes(32, byteorder=
'big')
◆ g1_to_json_dict()
Dict[str, Any] zeth.core.signing.g1_to_json_dict |
( |
G1 |
group_el | ) |
|
◆ gen_signing_keypair()
Return a one-time signature key-pair
composed of elements of F_q and G1.
Definition at line 93 of file signing.py.
95 Return a one-time signature key-pair
96 composed of elements of F_q and G1.
98 key_size_byte = ceil(len(
"{0:b}".format(ec.curve_order)) / 8)
100 int(
bytes(urandom(key_size_byte)).hex(), 16) % ec.curve_order)
102 int(
bytes(urandom(key_size_byte)).hex(), 16) % ec.curve_order)
103 X = ec.multiply(ec.G1, x.n)
104 Y = ec.multiply(ec.G1, y.n)
107 sk = SigningSecretKey(x, y, Y)
108 vk = SigningVerificationKey(X, Y)
109 return SigningKeyPair(sk, vk)
◆ sign()
Generate a Schnorr signature on a message m.
We assume here that the message fits in an Ethereum word (i.e. bit_len(m)
<= 256), so that it can be represented by a single bytes32 on the smart-
contract during the signature verification.
Definition at line 123 of file signing.py.
124 sk: SigningSecretKey,
125 m: bytes) -> Signature:
127 Generate a Schnorr signature on a message m.
128 We assume here that the message fits in an Ethereum word (i.e. bit_len(m)
129 <= 256), so that it can be represented by a single bytes32 on the smart-
130 contract during the signature verification.
137 challenge =
int(sha256(challenge_to_hash).hexdigest(), 16)
138 challenge = challenge % ec.curve_order
141 sigma = (sk.ssk[0].n + challenge * sk.psk.n) % ec.curve_order
◆ signature_as_mix_parameter()
int zeth.core.signing.signature_as_mix_parameter |
( |
Signature |
signature | ) |
|
Transform a signature to the format required by the mix function.
Definition at line 183 of file signing.py.
185 Transform a signature to the format required by the mix function.
◆ signature_from_bytes()
Signature zeth.core.signing.signature_from_bytes |
( |
bytes |
sig_bytes | ) |
|
Definition at line 119 of file signing.py.
120 return int.from_bytes(sig_bytes, byteorder=
'big')
◆ signature_from_mix_parameter()
Signature zeth.core.signing.signature_from_mix_parameter |
( |
int |
param | ) |
|
Transform mix function parameters to a signature.
Definition at line 192 of file signing.py.
194 Transform mix function parameters to a signature.
◆ signature_to_bytes()
bytes zeth.core.signing.signature_to_bytes |
( |
Signature |
signature | ) |
|
Definition at line 115 of file signing.py.
116 return signature.to_bytes(32, byteorder=
'big')
◆ verification_key_as_mix_parameter()
Transform a verification key to the format required by the mix function.
Definition at line 166 of file signing.py.
168 Transform a verification key to the format required by the mix function.
170 return [
int(vk.ppk[0]),
int(vk.ppk[1]),
int(vk.spk[0]),
int(vk.spk[1])]
◆ verification_key_from_mix_parameter()
Transform mix function parameter to verification key.
Definition at line 173 of file signing.py.
174 param: List[int]) -> SigningVerificationKey:
176 Transform mix function parameter to verification key.
178 return SigningVerificationKey(
179 (
FQ(param[0]),
FQ(param[1])),
180 (
FQ(param[2]),
FQ(param[3])))
◆ verify()
Return true if the signature sigma is valid on message m and vk.
We assume here that the message is an hexadecimal string written in
less than 256 bits to conform with Ethereum bytes32 type.
Definition at line 145 of file signing.py.
146 vk: SigningVerificationKey,
150 Return true if the signature sigma is valid on message m and vk.
151 We assume here that the message is an hexadecimal string written in
152 less than 256 bits to conform with Ethereum bytes32 type.
157 challenge =
int(sha256(challenge_to_hash).hexdigest(), 16)
158 challenge = challenge % ec.curve_order
160 left_part = ec.multiply(ec.G1,
FQ(sigma).n)
161 right_part = ec.add(vk.spk, ec.multiply(vk.ppk,
FQ(challenge).n))
163 return ec.eq(left_part, right_part)
◆ FQ
zeth.core.signing.FQ = ec.FQ |
◆ G1
zeth.core.signing.G1 = Tuple[ec.FQ, ec.FQ] |
◆ Signature
zeth.core.signing.Signature = int |
G1 g1_from_json_dict(Dict[str, Any] json_dict)
bytes signature_to_bytes(Signature signature)
SigningKeyPair gen_signing_keypair()
str fq_to_hex(FQ fq_element)
bool verify(SigningVerificationKey vk, bytes m, int sigma)
Signature signature_from_mix_parameter(int param)
bytes g1_to_bytes(G1 group_el)
Signature signature_from_bytes(bytes sig_bytes)
int signature_as_mix_parameter(Signature signature)
Dict[str, Any] g1_to_json_dict(G1 group_el)
FQ fq_from_bytes(bytes fq_bytes)
bytes fq_to_bytes(FQ fq_element)
List[int] verification_key_as_mix_parameter(SigningVerificationKey vk)
FQ fq_from_hex(str fq_hex)
SigningVerificationKey verification_key_from_mix_parameter(List[int] param)
Signature sign(SigningSecretKey sk, bytes m)