def fromSeed(seed = None): if seed is None: seed = os.urandom(MIN_SEED_LEN) if len(seed) < MIN_SEED_LEN: raise ValueError("HDPrivateKey seed must be at least 32 bytes long") signed64 = hmac.new(HMAC_MAGIC_KEY, seed, hashlib.sha512).digest() return HDPrivateKey(privkey = PrivateKey.from_bytes(signed64[:32]), chain = signed64[32:])
def fromSeed(seed=None): if seed is None: seed = os.urandom(MIN_SEED_LEN) if len(seed) < MIN_SEED_LEN: raise ValueError( "HDPrivateKey seed must be at least 32 bytes long") signed64 = hmac.new(HMAC_MAGIC_KEY, seed, hashlib.sha512).digest() return HDPrivateKey(privkey=PrivateKey.from_bytes(signed64[:32]), chain=signed64[32:])
def from_string(b58_str): data = utils.encoding.a2b_hashed_base58(b58_str) # TODO checksum? chain = data[HDPrivateKey.ChainCodeStart : HDPrivateKey.ChainCodeEnd] depth = int_from_bytes(data[HDPrivateKey.DepthStart : HDPrivateKey.DepthEnd]) index = int_from_bytes(data[HDPrivateKey.ChildIndexStart : HDPrivateKey.ChildIndexEnd]) parent = int_from_bytes(data[HDPrivateKey.ParentFingerPrintStart : HDPrivateKey.ParentFingerPrintEnd]) # The version field is used to deduce the network: version = int_from_bytes(data[HDPrivateKey.VersionStart:HDPrivateKey.VersionEnd]) network = networks.find(version, 'hd_private_key') privkey = PrivateKey.from_bytes(data[HDPrivateKey.PrivateKeyStart : HDPrivateKey.PrivateKeyEnd], network) return HDPrivateKey(privkey, chain, depth, index, parent, network)
def from_string(b58_str): data = utils.encoding.a2b_hashed_base58(b58_str) # TODO checksum? chain = data[HDPrivateKey.ChainCodeStart:HDPrivateKey.ChainCodeEnd] depth = int_from_bytes( data[HDPrivateKey.DepthStart:HDPrivateKey.DepthEnd]) index = int_from_bytes( data[HDPrivateKey.ChildIndexStart:HDPrivateKey.ChildIndexEnd]) parent = int_from_bytes( data[HDPrivateKey.ParentFingerPrintStart:HDPrivateKey. ParentFingerPrintEnd]) # The version field is used to deduce the network: version = int_from_bytes( data[HDPrivateKey.VersionStart:HDPrivateKey.VersionEnd]) network = Network.get_by_field('hd_private_key', version) privkey = PrivateKey.from_bytes( data[HDPrivateKey.PrivateKeyStart:HDPrivateKey.PrivateKeyEnd], network) return HDPrivateKey(privkey, chain, depth, index, parent, network)