Extract some SpendingKey methods into mixins that will be used by ZIP 32 classes.
Also use hex, not octal byte constants. Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
61f7f70e7a
commit
f024c7dd8f
|
@ -51,22 +51,8 @@ def cached(f):
|
||||||
return self._cached[f]
|
return self._cached[f]
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
class SpendingKey(object):
|
|
||||||
def __init__(self, data):
|
|
||||||
self.data = data
|
|
||||||
|
|
||||||
@cached
|
|
||||||
def ask(self):
|
|
||||||
return to_scalar(prf_expand(self.data, b'\0'))
|
|
||||||
|
|
||||||
@cached
|
|
||||||
def nsk(self):
|
|
||||||
return to_scalar(prf_expand(self.data, b'\1'))
|
|
||||||
|
|
||||||
@cached
|
|
||||||
def ovk(self):
|
|
||||||
return prf_expand(self.data, b'\2')[:32]
|
|
||||||
|
|
||||||
|
class DerivedAkNk(object):
|
||||||
@cached
|
@cached
|
||||||
def ak(self):
|
def ak(self):
|
||||||
return SPENDING_KEY_BASE * self.ask()
|
return SPENDING_KEY_BASE * self.ask()
|
||||||
|
@ -75,10 +61,29 @@ class SpendingKey(object):
|
||||||
def nk(self):
|
def nk(self):
|
||||||
return PROVING_KEY_BASE * self.nsk()
|
return PROVING_KEY_BASE * self.nsk()
|
||||||
|
|
||||||
|
|
||||||
|
class DerivedIvk(object):
|
||||||
@cached
|
@cached
|
||||||
def ivk(self):
|
def ivk(self):
|
||||||
return Fr(crh_ivk(bytes(self.ak()), bytes(self.nk())))
|
return Fr(crh_ivk(bytes(self.ak()), bytes(self.nk())))
|
||||||
|
|
||||||
|
|
||||||
|
class SpendingKey(DerivedAkNk, DerivedIvk):
|
||||||
|
def __init__(self, data):
|
||||||
|
self.data = data
|
||||||
|
|
||||||
|
@cached
|
||||||
|
def ask(self):
|
||||||
|
return to_scalar(prf_expand(self.data, b'\x00'))
|
||||||
|
|
||||||
|
@cached
|
||||||
|
def nsk(self):
|
||||||
|
return to_scalar(prf_expand(self.data, b'\x01'))
|
||||||
|
|
||||||
|
@cached
|
||||||
|
def ovk(self):
|
||||||
|
return prf_expand(self.data, b'\x02')[:32]
|
||||||
|
|
||||||
@cached
|
@cached
|
||||||
def default_d(self):
|
def default_d(self):
|
||||||
i = 0
|
i = 0
|
||||||
|
|
Loading…
Reference in New Issue