Ejemplo n.º 1
0
def trytes_to_ascii(trytes):
    message = ''
    value = ''
    timestamp = ''
    tag = ''
    for m in range(2, 2188):
        message = TryteString(message + trytes[m])
    for l in range(2270, 2297):
        value = TryteString(value + trytes[l])
    for n in range(2594, 2621):
        tag = TryteString(tag + trytes[n])
    for o in range(2324, 2333):
        timestamp = TryteString(timestamp + trytes[o])
    return message.decode(), str(tag), int(int_from_trits(
        value.as_trits())), int(int_from_trits(timestamp.as_trits()))
Ejemplo n.º 2
0
def validate_signature_fragments(
        fragments: Sequence[TryteString],
        hash_: Hash,
        public_key: TryteString,
        sponge_type: type = Kerl,
) -> bool:
    """
    Returns whether a sequence of signature fragments is valid.

    :param fragments:
      Sequence of signature fragments (usually
      :py:class:`iota.transaction.Fragment` instances).

    :param hash_:
      Hash used to generate the signature fragments (usually a
      :py:class:`iota.transaction.BundleHash` instance).

    :param public_key:
      The public key value used to verify the signature digest (usually a
      :py:class:`iota.types.Address` instance).

    :param sponge_type:
      The class used to create the cryptographic sponge (i.e., Curl or Kerl).
    """
    checksum = [0] * (HASH_LENGTH * len(fragments))
    normalized_hash = normalize(hash_)

    for i, fragment in enumerate(fragments):
        outer_sponge = sponge_type()

        # If there are more than 3 iterations, loop back around to the
        # start.
        normalized_chunk = normalized_hash[i % len(normalized_hash)]

        buffer = []
        for j, hash_trytes in enumerate(fragment.iter_chunks(Hash.LEN)):
            buffer: List[int] = hash_trytes.as_trits()
            inner_sponge = sponge_type()

            # Note the sign flip compared to
            # :py;class:`SignatureFragmentGenerator`.
            for _ in range(13 + normalized_chunk[j]):
                inner_sponge.reset()
                inner_sponge.absorb(buffer)
                inner_sponge.squeeze(buffer)

            outer_sponge.absorb(buffer)

        outer_sponge.squeeze(buffer)
        checksum[i * HASH_LENGTH:(i + 1) * HASH_LENGTH] = buffer

    actual_public_key = [0] * HASH_LENGTH
    addy_sponge = sponge_type()
    addy_sponge.absorb(checksum)
    addy_sponge.squeeze(actual_public_key)

    return actual_public_key == public_key.as_trits()
Ejemplo n.º 3
0
def trailing_zeros(trytes):
    trytes = TryteString(trytes)
    trits = trytes.as_trits()
    n = len(trits) - 1
    z = 0
    for i in range(0, n):
        if trits[n - i] == 0:
            z += 1
        else:
            break
    return z
Ejemplo n.º 4
0
    def digest(self, sponge_type, normalized_bundle_fragment: List[int],
               signature_fragment: iota.TryteString):
        hash = sponge_type()
        trits = signature_fragment.as_trits()
        d = []

        for j in range(self.NUMBER_OF_FRAGMENT_CHUNKS):
            for k in range(normalized_bundle_fragment[j] -
                           self.MIN_TRYTE_VALUE):
                hash.reset()
                hash.absorb(trits, j * HASH_LENGTH, (j + 1) * HASH_LENGTH)
                hash.squeeze(trits, j * HASH_LENGTH)

        hash.reset()
        hash.absorb(trits)
        hash.squeeze(d)

        return d