iota/crypto/signing.py
def validate_signature_fragments(
        fragments,
        hash_,
        public_key,
        sponge_type=Kerl,
):
    # type: (Sequence[TryteString], Hash, TryteString, type) -> 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 = hash_trytes.as_trits()  # type: List[int]
            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()
def validate_signature_fragments(
        fragments,
        hash_,
        public_key,
        sponge_type=Kerl,
):
    # type: (Sequence[TryteString], Hash, TryteString, type) -> bool
    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 = hash_trytes.as_trits()  # type: List[int]
            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()
def validate_signature_fragments ( fragments , hash_ , public_key , sponge_type = Kerl , ) : # type: (Sequence[TryteString], Hash, TryteString, type) -> bool 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 = hash_trytes . as_trits ( ) # type: List[int] 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 ( )
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).
Returns whether a sequence of signature fragments is valid .