コード例 #1
0
 def child(self, index, hardened=False):
     if index >= 0x80000000:
         raise ValueError('child number should always be less than 2^31')
     sec = self.private_key.point.sec()
     fingerprint = hash160(sec)[:4]
     if hardened:
         index += 0x80000000
         pk = self.private_key.secret.to_bytes(32, 'big')
         data = b'\x00' + pk + index.to_bytes(4, 'big')
         raw = HMAC(key=self.chain_code, msg=data,
                    digestmod=sha512).digest()
     else:
         data = sec + index.to_bytes(4, 'big')
         raw = HMAC(key=self.chain_code, msg=data,
                    digestmod=sha512).digest()
     secret = (int.from_bytes(raw[:32], 'big') +
               self.private_key.secret) % N
     private_key = PrivateKey(
         secret=secret,
         compressed=True,
         testnet=self.testnet,
     )
     chain_code = raw[32:]
     depth = self.depth + 1
     child_number = index
     return HDPrivateKey(
         private_key=private_key,
         chain_code=chain_code,
         depth=depth,
         fingerprint=fingerprint,
         child_number=child_number,
     )
コード例 #2
0
 def h160(self, coin='ela'):
     _pubkey = self.to_bytes()
     _redeemscript = _pubkey
     if coin == 'ela':
         _redeemscript = bytes([len(_pubkey)]) + _pubkey + bytes.fromhex(
             'ac')
     elif coin == 'did':
         _redeemscript = bytes([len(_pubkey)]) + _pubkey + bytes.fromhex(
             'ad')
     return hash160(_redeemscript)
コード例 #3
0
 def child(self, index):
     if index >= 0x80000000:
         raise ValueError('child number should always be less than 2^31')
     sec = self.point.sec()
     data = sec + index.to_bytes(4, 'big')
     raw = HMAC(key=self.chain_code, msg=data, digestmod=sha512).digest()
     point = PrivateKey(int.from_bytes(raw[:32], 'big')).point + self.point
     chain_code = raw[32:]
     depth = self.depth + 1
     fingerprint = hash160(sec)[:4]
     child_number = index
     return HDPublicKey(
         point=point,
         chain_code=chain_code,
         depth=depth,
         fingerprint=fingerprint,
         child_number=child_number,
     )
コード例 #4
0
ファイル: ecc.py プロジェクト: bocheng0000/elastos-tools
 def segwit_address(self, prefix=b'\x05'):
     address_bytes = hash160(self.segwit_redeem_script()[1:])
     return encode_base58_checksum(prefix + address_bytes)
コード例 #5
0
ファイル: ecc.py プロジェクト: bocheng0000/elastos-tools
 def h160(self, compressed=True):
     return hash160(self.sec(compressed))