def _checksum(self):
     if self._type.__eq__(UnlockHashType.NIL):
         return bytes(jsarr.new_array(UnlockHash._CHECKSUM_SIZE))
     e = RivineBinaryEncoder()
     e.add_int8(self._type.value)
     e.add(self._hash)
     return jscrypto.blake2b(e.data)
예제 #2
0
 def signature_hash_get(self, *extra_objects):
     """
     signature_hash_get is used to get the signature hash for this Transaction,
     which are used to proof the authenticity of the transaction.
     """
     input = self._signature_hash_input_get(*extra_objects)
     return blake2b(input)
 def _custom_unlockhash_getter(self):
     uhs = sorted(self.unlockhashes, key=lambda uh: str(uh))
     tree = MerkleTree(hash_func=lambda o: jscrypto.blake2b(o))
     tree.push(sia_encode_all(len(uhs)))
     for uh in uhs:
         tree.push(sia_encode_all(uh))
     tree.push(sia_encode_all(self.required_signatures))
     return UnlockHash(uhtype=UnlockHashType.MULTI_SIG, uhhash=tree.root())
 def _custom_unlockhash_getter(self):
     e = RivineBinaryEncoder()
     self.sia_binary_encode_data(e)
     # need to encode again to add the length
     data = e.data
     e = SiaBinaryEncoder()
     e.add_slice(data)
     hash = jscrypto.blake2b(e.data)
     return UnlockHash(uhtype=UnlockHashType.ATOMIC_SWAP, uhhash=hash)
예제 #5
0
 def _id_new(self, specifier=None, index=None):
     encoder = SiaBinaryEncoder()
     if specifier != None:
         encoder.add_array(specifier)
     encoder.add_array(self._id_input_compute())
     if index != None:
         encoder.add_int(index)
     hash = blake2b(encoder.data)
     return Hash(value=hash)
예제 #6
0
 def from_unlockhash(cls, unlockhash):
     """
     Create an ERC20 Address from a TFT Address (type: UnlockHash).
     """
     if isinstance(unlockhash, str):
         raise TypeError("unlockhash has to be already decoded from str before calling this func")
     e = SiaBinaryEncoder()
     unlockhash.sia_binary_encode(e)
     hash = jscrypto.blake2b(e.data)
     return cls(value=jsarr.slice_array(hash, Hash.SIZE-ERC20Address.SIZE))
예제 #7
0
 def unlockhash(self):
     """
     Return the unlock hash generated from this public key.
     """
     e = SiaBinaryEncoder()
     self.sia_binary_encode(e)
     # need to encode again to add the length
     data = e.data
     e = SiaBinaryEncoder()
     e.add_slice(data)
     hash = jscrypto.blake2b(e.data)
     return UnlockHash(uhtype=UnlockHashType.PUBLIC_KEY, uhhash=hash)