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:
Daira Hopwood 2018-07-21 14:17:20 +01:00
parent 61f7f70e7a
commit f024c7dd8f
1 changed files with 20 additions and 15 deletions

View File

@ -51,22 +51,8 @@ def cached(f):
return self._cached[f]
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
def ak(self):
return SPENDING_KEY_BASE * self.ask()
@ -75,10 +61,29 @@ class SpendingKey(object):
def nk(self):
return PROVING_KEY_BASE * self.nsk()
class DerivedIvk(object):
@cached
def ivk(self):
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
def default_d(self):
i = 0