Refactor Zcash SLIP 44 coin type and the `hardened` function into a separate file,
since they are not specific to Sapling. Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
cc3376f37e
commit
060ea786f7
|
@ -0,0 +1,7 @@
|
|||
# Common definitions for hierarchical derivation.
|
||||
|
||||
ZCASH_MAIN_COINTYPE = 133
|
||||
|
||||
def hardened(i):
|
||||
assert 0 <= i and i < (1<<31)
|
||||
return i + (1<<31)
|
|
@ -5,6 +5,8 @@ from hashlib import blake2b
|
|||
|
||||
from .key_components import to_scalar, prf_expand, diversify_hash, DerivedAkNk, DerivedIvk
|
||||
from .generators import SPENDING_KEY_BASE, PROVING_KEY_BASE
|
||||
|
||||
from ..hd_common import hardened
|
||||
from ..utils import i2leosp, i2lebsp, lebs2osp
|
||||
from ..ff1 import ff1_aes256_encrypt
|
||||
from ..output import render_args, render_tv, option, Some
|
||||
|
@ -219,11 +221,6 @@ class ExtendedFullViewingKey(DerivedIvk, ExtendedBase):
|
|||
return self.__class__(self.ak(), nk_internal, ovk_internal, dk_internal, self._c, self.depth(), self.parent_tag(), self._i)
|
||||
|
||||
|
||||
def hardened(i):
|
||||
assert(i < (1<<31))
|
||||
return i + (1<<31)
|
||||
|
||||
|
||||
def main():
|
||||
args = render_args()
|
||||
|
||||
|
|
|
@ -10,9 +10,11 @@ from .output import render_args, render_tv, Some
|
|||
from .rand import Rand, randbytes
|
||||
from .orchard import key_components as orchard_key_components
|
||||
from .sapling import zip32 as sapling_zip32
|
||||
from .hd_common import ZCASH_MAIN_COINTYPE, hardened
|
||||
from .unified_encoding import encode_unified, decode_unified
|
||||
from .unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM
|
||||
|
||||
|
||||
def main():
|
||||
args = render_args()
|
||||
|
||||
|
@ -37,9 +39,9 @@ def main():
|
|||
has_s_key = rand.bool()
|
||||
if has_s_key:
|
||||
root_key = sapling_zip32.ExtendedSpendingKey.master(seed)
|
||||
purpose_key = root_key.child(sapling_zip32.hardened(32))
|
||||
coin_key = purpose_key.child(sapling_zip32.hardened(133))
|
||||
account_key = coin_key.child(sapling_zip32.hardened(i))
|
||||
purpose_key = root_key.child(hardened(32))
|
||||
coin_key = purpose_key.child(hardened(ZCASH_MAIN_COINTYPE))
|
||||
account_key = coin_key.child(hardened(i))
|
||||
sapling_fvk = account_key.to_extended_fvk()
|
||||
|
||||
sapling_fvk_bytes = b"".join([
|
||||
|
|
|
@ -10,9 +10,11 @@ from .output import render_args, render_tv, Some
|
|||
from .rand import Rand, randbytes
|
||||
from .orchard import key_components as orchard_key_components
|
||||
from .sapling import zip32 as sapling_zip32
|
||||
from .hd_common import ZCASH_MAIN_COINTYPE, hardened
|
||||
from .unified_encoding import encode_unified, decode_unified
|
||||
from .unified_encoding import P2PKH_ITEM, SAPLING_ITEM, ORCHARD_ITEM
|
||||
|
||||
|
||||
def main():
|
||||
args = render_args()
|
||||
|
||||
|
@ -37,9 +39,9 @@ def main():
|
|||
has_s_key = rand.bool()
|
||||
if has_s_key:
|
||||
root_key = sapling_zip32.ExtendedSpendingKey.master(seed)
|
||||
purpose_key = root_key.child(sapling_zip32.hardened(32))
|
||||
coin_key = purpose_key.child(sapling_zip32.hardened(133))
|
||||
account_key = coin_key.child(sapling_zip32.hardened(i))
|
||||
purpose_key = root_key.child(hardened(32))
|
||||
coin_key = purpose_key.child(hardened(ZCASH_MAIN_COINTYPE))
|
||||
account_key = coin_key.child(hardened(i))
|
||||
sapling_dk = account_key.to_extended_fvk().dk()
|
||||
sapling_ivk = account_key.ivk()
|
||||
sapling_ivk_bytes = bytes(sapling_dk) + bytes(sapling_ivk)
|
||||
|
|
Loading…
Reference in New Issue