public static function decodeCredential(string $json, string $responseType) : PublicKeyCredential
    {
        $decoded = json_decode($json, true, 10);
        if ($decoded === false) {
            throw new ParseException('Failed to decode PublicKeyCredential Json');
        }

        if (($decoded['type'] ?? null) !== PublicKeyCredentialType::PUBLIC_KEY) {
            throw new ParseException("Expecting type 'public-key'");
        }

        if (empty($decoded['id'])) {
            throw new ParseException('Missing id in json data');
        }
        $id = $decoded['id'];
        if (!is_string($id)) {
            throw new ParseException('Id in json data should be string');
        }

        $rawId = Base64UrlEncoding::decode($id);

        $responseData = $decoded['response'] ?? null;
        if (!is_array($responseData)) {
            throw new ParseException('Expecting array data for response');
        }

        $response = self::decodeResponse($responseData, $responseType);


        // TODO: clientExtensionResults

        return new PublicKeyCredential(new ByteBuffer($rawId), $response);
    }