7 from __future__
import annotations
9 from zeth.core.utils import hex_extend_32bytes, digest_to_binary_string, \
12 from Crypto
import Random
13 from hashlib
import blake2s
14 from typing
import NewType
18 OwnershipSecretKey = NewType(
'OwnershipSecretKey', bytes)
22 OwnershipPublicKey = NewType(
'OwnershipPublicKey', bytes)
27 Key-pair for ownership proof. This represents the 'payment key' (apk)
28 from the 'payment address' and the 'spending key' (ask) from the
29 'private address'. These are components of ZethAddress, used in
30 note commitments in the joinsplit statement.
32 def __init__(self, a_sk: OwnershipSecretKey, a_pk: OwnershipPublicKey):
33 self.a_sk: OwnershipSecretKey = a_sk
34 self.a_pk: OwnershipPublicKey = a_pk
39 Convert either a secret or public ownership key to hex representation of the
40 underlying 32-byte object.
47 Read an ownership public key from a hex string.
54 Read an ownership public key from a hex string.
61 a_pk = _derive_a_pk(a_sk)
66 def _derive_a_pk(a_sk: OwnershipSecretKey) -> OwnershipPublicKey:
68 Returns a_pk = blake2s(1100 || [a_sk]_252 || 0^256)
71 first_252bits_ask = binary_a_sk[:252]
72 left_leg_bin =
"1100" + first_252bits_ask
73 left_leg_hex =
"{0:0>4X}".format(
int(left_leg_bin, 2))
74 zeroes =
"0000000000000000000000000000000000000000000000000000000000000000"
77 [
"bytes32",
"bytes32"],
78 [bytes.fromhex(left_leg_hex), bytes.fromhex(zeroes)])