public function verifyLastHash(
        Blakechain $chain,
        string $lastHash
    ): bool {
        /**
         * @var array<int, Node> $nodes
         */
        $nodes = $chain->getNodes();
        $count = \count($nodes);

        $prevHash = '';
        for ($i = 0; $i < $count; ++$i) {
            /** @var Node $curr */
            $curr = $nodes[$i];
            $actualHash = SodiumCompat::crypto_generichash(
                $curr->getData(),
                $prevHash
            );
            if (!\hash_equals($actualHash, $curr->getHash(true))) {
                $this->lastErrorData = [
                    'index' => $i,
                    'item' => [
                        'prev' => $curr->getPrevHash(),
                        'data' => $curr->getData(),
                        'hash' => $curr->getHash()
                    ],
                    'failure' => static::HASH_DOES_NOT_MATCH
                ];
                return false;
            }
            $prevHash = $curr->getHash(true);
        }
        $decoded = Base64UrlSafe::decode($lastHash);
        if (!\hash_equals($prevHash, $decoded)) {
            $this->lastErrorData = [
                'item' => null,
                'expected' => $lastHash,
                'calculated' => Base64UrlSafe::encode($prevHash),
                'failure' => static::FINAL_HASH_MISMATCH
            ];
            return false;
        }
        return true;
    }