{
    "Function": "verify",
    "File": "src/WebAuthnSol/WebAuthn.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "LibString",
        "FCL",
        "Base64",
        "LibString"
    ],
    "Internal Calls": [
        "sha256(bytes)",
        "keccak256(bytes)",
        "abi.encode()",
        "abi.decode()",
        "keccak256(bytes)",
        "string.concat()",
        "abi.encodePacked()",
        "sha256(bytes)",
        "keccak256(bytes)"
    ],
    "Library Calls": [
        "encodeURL",
        "slice",
        "ecdsa_verify",
        "slice"
    ],
    "Low-Level Calls": [
        "staticcall"
    ],
    "Code": "function verify(bytes memory challenge, bool requireUV, WebAuthnAuth memory webAuthnAuth, uint256 x, uint256 y)\n        internal\n        view\n        returns (bool)\n    {\n        if (webAuthnAuth.s > P256_N_DIV_2) {\n            // guard against signature malleability\n            return false;\n        }\n\n        // 11. Verify that the value of C.type is the string webauthn.get.\n        // bytes(\"type\":\"webauthn.get\").length = 21\n        string memory _type = webAuthnAuth.clientDataJSON.slice(webAuthnAuth.typeIndex, webAuthnAuth.typeIndex + 21);\n        if (keccak256(bytes(_type)) != EXPECTED_TYPE_HASH) {\n            return false;\n        }\n\n        // 12. Verify that the value of C.challenge equals the base64url encoding of options.challenge.\n        bytes memory expectedChallenge = bytes(string.concat('\"challenge\":\"', Base64.encodeURL(challenge), '\"'));\n        string memory actualChallenge = webAuthnAuth.clientDataJSON.slice(\n            webAuthnAuth.challengeIndex, webAuthnAuth.challengeIndex + expectedChallenge.length\n        );\n        if (keccak256(bytes(actualChallenge)) != keccak256(expectedChallenge)) {\n            return false;\n        }\n\n        // Skip 13., 14., 15.\n\n        // 16. Verify that the UP bit of the flags in authData is set.\n        if (webAuthnAuth.authenticatorData[32] & AUTH_DATA_FLAGS_UP != AUTH_DATA_FLAGS_UP) {\n            return false;\n        }\n\n        // 17. If user verification is required for this assertion, verify that the User Verified bit of the flags in authData is set.\n        if (requireUV && (webAuthnAuth.authenticatorData[32] & AUTH_DATA_FLAGS_UV) != AUTH_DATA_FLAGS_UV) {\n            return false;\n        }\n\n        // skip 18.\n\n        // 19. Let hash be the result of computing a hash over the cData using SHA-256.\n        bytes32 clientDataJSONHash = sha256(bytes(webAuthnAuth.clientDataJSON));\n\n        // 20. Using credentialPublicKey, verify that sig is a valid signature over the binary concatenation of authData and hash.\n        bytes32 messageHash = sha256(abi.encodePacked(webAuthnAuth.authenticatorData, clientDataJSONHash));\n        bytes memory args = abi.encode(messageHash, webAuthnAuth.r, webAuthnAuth.s, x, y);\n        // try the RIP-7212 precompile address\n        (bool success, bytes memory ret) = VERIFIER.staticcall(args);\n        // staticcall will not revert if address has no code\n        // check return length\n        // note that even if precompile exists, ret.length is 0 when verification returns false\n        // so an invalid signature will be checked twice: once by the precompile and once by FCL.\n        // Ideally this signature failure is simulated offchain and no one actually pay this gas.\n        bool valid = ret.length > 0;\n        if (success && valid) return abi.decode(ret, (uint256)) == 1;\n\n        return FCL.ecdsa_verify(messageHash, webAuthnAuth.r, webAuthnAuth.s, x, y);\n    }"
}