Example #1
0
 def _outputid_new(self, specifier, index):
     encoder = encoder_sia_get()
     encoder.add_array(specifier)
     encoder.add_array(self._id_input_compute())
     encoder.add_int(index)
     hash = bytearray.fromhex(blake2_string(encoder.data))
     return Hash(value=hash)
Example #2
0
 def _checksum(self):
     if self._type == UnlockHashType.NIL:
         return b'\x00'*UnlockHash._CHECKSUM_SIZE
     e = encoder_rivine_get()
     e.add_int8(int(self._type))
     e.add(self._hash)
     return bytearray.fromhex(blake2_string(e.data))
Example #3
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 bytes.fromhex(blake2_string(input))
Example #4
0
 def from_unlockhash(cls, unlockhash):
     """
     Create an ERC20 Address from a TFT Address (type: UnlockHash).
     """
     e = encoder_sia_get()
     unlockhash.sia_binary_encode(e)
     hash = bytes.fromhex(blake2_string(e.data))
     return cls(value=hash[Hash.SIZE - ERC20Address.SIZE:])
Example #5
0
 def unlockhash(self):
     uhs = sorted(self.unlockhashes, key=lambda uh: str(uh))
     tree = MerkleTree(hash_func=lambda o: bytes.fromhex(blake2_string(o)))
     tree.push(sia_encode(len(uhs)))
     for uh in uhs:
         tree.push(sia_encode(uh))
     tree.push(sia_encode(self.required_signatures))
     return UnlockHash(type=UnlockHashType.MULTI_SIG, hash=tree.root())
Example #6
0
 def unlockhash(self):
     e = encoder_rivine_get()
     self.sia_binary_encode_data(e)
     # need to encode again to add the length
     data = e.data
     e = encoder_sia_get()
     e.add_slice(data)
     hash = bytearray.fromhex(blake2_string(e.data))
     return UnlockHash(type=UnlockHashType.ATOMIC_SWAP, hash=hash)
Example #7
0
def test_basic_merkletree():
    tree = Tree(hash_func=lambda o: bytes.fromhex(blake2_string(o)))
    tree.push(bytearray([1]))
    tree.push(bytearray([2]))
    tree.push(bytearray([3]))
    tree.push(bytearray([4]))
    tree.push(bytearray([5]))
    root = tree.root().hex()
    assert root == '0002789a97a9feee38af3709f06377ef0ad7d91407cbcad1ccb8605556b6578e'
    print('Root is {}'.format(root))
Example #8
0
 def unlockhash(self):
     """
     Return the unlock hash generated from this public key.
     """
     e = encoder_sia_get()
     self.sia_binary_encode(e)
     # need to encode again to add the length
     data = e.data
     e = encoder_sia_get()
     e.add_slice(data)
     hash = bytearray.fromhex(blake2_string(e.data))
     return UnlockHash(type=UnlockHashType.PUBLIC_KEY, hash=hash)
Example #9
0
    def register(self, threebot_id, reservation, signature):
        record = self._tfclient.threebot.record_get(threebot_id)
        threebot_id = record.identifier

        if not isinstance(threebot_id, int):
            raise TypeError(
                "threebot_id must be an int. The unique identifier of the theebot, not its same"
            )
        if threebot_id <= 0:
            raise TypeError("threebot_id cannot be negative")

        buff = BytesIO()
        bi = threebot_id.to_bytes(64, byteorder='big')
        buff.write(bi)

        if isinstance(reservation, str):
            reservation = reservation.encode('utf-8')
        buff.write(reservation)
        h = blake2_string(buff.getvalue(), 32)

        self._store[h] = reservation

        return Hash(h)