def to_string(self): # See BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki bytes = ("" + to_bytes(self.network.hd_public_key, length=4) + to_bytes(self.depth, length=1) + to_bytes(self.parent, length=4) + to_bytes(self.index, length=4) + self.chain + self.to_public_key().to_bytes()) return utils.encoding.b2a_hashed_base58(bytes)
def to_string(self): # See BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki bytes = ( "" + to_bytes(self.network.hd_private_key, length=4) + to_bytes(self.depth, length=1) + to_bytes(self.parent, length=4) + to_bytes(self.index, length=4) + self.chain + '\0' # this zero is prepended to private keys. HDPublicKey doesn't do it + self.to_private_key().to_bytes()) return utils.encoding.b2a_hashed_base58(bytes)
def to_string(self): # See BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki bytes = ("" + to_bytes(self.network.hd_public_key, length = 4) + to_bytes(self.depth, length = 1) + to_bytes(self.parent, length = 4) + to_bytes(self.index, length = 4) + self.chain + self.to_public_key().to_bytes() ) return utils.encoding.b2a_hashed_base58(bytes)
def to_string(self): # See BIP 32: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki bytes = ("" + to_bytes(self.network.hd_private_key, length = 4) + to_bytes(self.depth, length = 1) + to_bytes(self.parent, length = 4) + to_bytes(self.index, length = 4) + self.chain + '\0' # this zero is prepended to private keys. HDPublicKey doesn't do it + self.to_private_key().to_bytes() ) return utils.encoding.b2a_hashed_base58(bytes)
def derive(self, index, hardened = False): # TODO Is index Valid? if index < HARDENED_START and hardened: index += HARDENED_START if hardened: raise ValueError("Hardened derivation is not posible on HDPublicKey") else: key = self.to_public_key().to_bytes() signed64 = hmac.new( self.chain, key + to_bytes(self.index, length = 4), hashlib.sha512 ).digest() x, y = self.pubkey.pair curve = utils.generator_secp256k1 point = int_from_bytes(signed64[:32]) * curve + utils.Point(curve.curve(), x, y, curve.order()) pubkey = PublicKey((point.x(), point.y()), self.network) chain = signed64[32:] depth = self.depth + 1 return HDPublicKey(pubkey, chain, depth, index, self.fingerprint, self.network)
def derive(self, index, hardened=False): # TODO Is index Valid? if index < HARDENED_START and hardened: index += HARDENED_START if hardened: raise ValueError( "Hardened derivation is not posible on HDPublicKey") else: key = self.to_public_key().to_bytes() signed64 = hmac.new(self.chain, key + to_bytes(self.index, length=4), hashlib.sha512).digest() x, y = self.pubkey.pair curve = utils.generator_secp256k1 point = int_from_bytes(signed64[:32]) * curve + utils.Point( curve.curve(), x, y, curve.order()) pubkey = PublicKey((point.x(), point.y()), self.network) chain = signed64[32:] depth = self.depth + 1 return HDPublicKey(pubkey, chain, depth, index, self.fingerprint, self.network)
def derive(self, index, hardened=False): # TODO Is index Valid? if index < HARDENED_START and hardened: index += HARDENED_START if hardened: key = '\0' + self.to_private_key().to_bytes( ) # a literal 0 is prepended to private keys else: key = self.to_public_key().to_bytes() signed64 = hmac.new(self.chain, key + to_bytes(self.index, length=4), hashlib.sha512).digest() seed = (int_from_bytes(signed64[:32]) + self.to_private_key().seed ) % utils.generator_secp256k1.order() privkey = PrivateKey(seed, self.network) chain = signed64[32:] depth = self.depth + 1 return HDPrivateKey(privkey, chain, depth, index, self.fingerprint, self.network)
def derive(self, index, hardened = False): # TODO Is index Valid? if index < HARDENED_START and hardened: index += HARDENED_START if hardened: key = '\0' + self.to_private_key().to_bytes() # a literal 0 is prepended to private keys else: key = self.to_public_key().to_bytes() signed64 = hmac.new( self.chain, key + to_bytes(self.index, length = 4), hashlib.sha512 ).digest() seed = (int_from_bytes(signed64[:32]) + self.to_private_key().seed) % utils.generator_secp256k1.order() privkey = PrivateKey(seed, self.network) chain = signed64[32:] depth = self.depth + 1 return HDPrivateKey(privkey, chain, depth, index, self.fingerprint, self.network)