public function verifySequenceHashes(
        Blakechain $chain,
        int $offset = 0,
        int $limit = PHP_INT_MAX
    ): bool {
        $subchain = $chain->getPartialChain($offset, $limit);

        /** @var string $prev */
        $prev = '';

        /**
         * @var int $idx
         * @var array<string, string> $item
         */
        foreach ($subchain as $idx => $item) {
            $prevHash = Base64UrlSafe::decode($item['prev']);
            $storedHash = Base64UrlSafe::decode($item['hash']);
            $actualHash = SodiumCompat::crypto_generichash(
                $item['data'],
                $prevHash
            );
            if (!\hash_equals($actualHash, $storedHash)) {
                $this->lastErrorData = [
                    'index' => $idx,
                    'item' => $item,
                    'failure' => static::HASH_DOES_NOT_MATCH
                ];
                return false;
            }
            if (!empty($prev)) {
                if (!\hash_equals($prev, $item['prev'])) {
                    $this->lastErrorData = [
                        'index' => $idx,
                        'prev' => $prev,
                        'item' => $item,
                        'failure' => static::PREV_DOES_NOT_MATCH
                    ];
                    return false;
                }
            }
            /** @var string $prev */
            $prev = $item['hash'];
        }
        return true;
    }
public function verifySequenceHashes(
        Blakechain $chain,
        int $offset = 0,
        int $limit = PHP_INT_MAX
    ): bool {
        $subchain = $chain->getPartialChain($offset, $limit);

        /** @var string $prev */
        $prev = '';

        /**
         * @var int $idx
         * @var array<string, string> $item
         */
        foreach ($subchain as $idx => $item) {
            $prevHash = Base64UrlSafe::decode($item['prev']);
            $storedHash = Base64UrlSafe::decode($item['hash']);
            $actualHash = SodiumCompat::crypto_generichash(
                $item['data'],
                $prevHash
            );
            if (!\hash_equals($actualHash, $storedHash)) {
                $this->lastErrorData = [
                    'index' => $idx,
                    'item' => $item,
                    'failure' => static::HASH_DOES_NOT_MATCH
                ];
                return false;
            }
            if (!empty($prev)) {
                if (!\hash_equals($prev, $item['prev'])) {
                    $this->lastErrorData = [
                        'index' => $idx,
                        'prev' => $prev,
                        'item' => $item,
                        'failure' => static::PREV_DOES_NOT_MATCH
                    ];
                    return false;
                }
            }
            /** @var string $prev */
            $prev = $item['hash'];
        }
        return true;
    }
public function verifySequenceHashes ( Blakechain $ chain , int $ offset = 0 , int $ limit = PHP_INT_MAX ) : bool { $ subchain = $ chain -> getPartialChain ( $ offset , $ limit ) ; /** @var string $prev */ $ prev = '' ; /**
         * @var int $idx
         * @var array<string, string> $item
         */ foreach ( $ subchain as $ idx => $ item ) { $ prevHash = Base64UrlSafe :: decode ( $ item [ 'prev' ] ) ; $ storedHash = Base64UrlSafe :: decode ( $ item [ 'hash' ] ) ; $ actualHash = SodiumCompat :: crypto_generichash ( $ item [ 'data' ] , $ prevHash ) ; if ( ! \ hash_equals ( $ actualHash , $ storedHash ) ) { $ this -> lastErrorData = [ 'index' => $ idx , 'item' => $ item , 'failure' => static :: HASH_DOES_NOT_MATCH ] ; return false ; } if ( ! empty ( $ prev ) ) { if ( ! \ hash_equals ( $ prev , $ item [ 'prev' ] ) ) { $ this -> lastErrorData = [ 'index' => $ idx , 'prev' => $ prev , 'item' => $ item , 'failure' => static :: PREV_DOES_NOT_MATCH ] ; return false ; } } /** @var string $prev */ $ prev = $ item [ 'hash' ] ; } return true ; }
This is a self-consistency check for a subset of a Blakechain.

@param Blakechain $chain
@param int $offset
@param int $limit
@return bool

@throws \SodiumException
This is a self - consistency check for a subset of a Blakechain .