{
    "Function": "slitherConstructorConstantVariables",
    "File": "src/WebAuthnSol/WebAuthn.sol",
    "Parent Contracts": [],
    "High-Level Calls": [],
    "Internal Calls": [
        "keccak256(bytes)"
    ],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "library WebAuthn {\n    using LibString for string;\n\n    struct WebAuthnAuth {\n        /// @dev The WebAuthn authenticator data.\n        ///      See https://www.w3.org/TR/webauthn-2/#dom-authenticatorassertionresponse-authenticatordata.\n        bytes authenticatorData;\n        /// @dev The WebAuthn client data JSON.\n        ///      See https://www.w3.org/TR/webauthn-2/#dom-authenticatorresponse-clientdatajson.\n        string clientDataJSON;\n        /// @dev The index at which \"challenge\":\"...\" occurs in `clientDataJSON`.\n        uint256 challengeIndex;\n        /// @dev The index at which \"type\":\"...\" occurs in `clientDataJSON`.\n        uint256 typeIndex;\n        /// @dev The r value of secp256r1 signature\n        uint256 r;\n        /// @dev The s value of secp256r1 signature\n        uint256 s;\n    }\n\n    /// @dev Bit 0 of the authenticator data struct, corresponding to the \"User Present\" bit.\n    ///      See https://www.w3.org/TR/webauthn-2/#flags.\n    bytes1 private constant AUTH_DATA_FLAGS_UP = 0x01;\n\n    /// @dev Bit 2 of the authenticator data struct, corresponding to the \"User Verified\" bit.\n    ///      See https://www.w3.org/TR/webauthn-2/#flags.\n    bytes1 private constant AUTH_DATA_FLAGS_UV = 0x04;\n\n    /// @dev Secp256r1 curve order / 2 used as guard to prevent signature malleability issue.\n    uint256 private constant P256_N_DIV_2 = FCL.n / 2;\n\n    /// @dev The precompiled contract address to use for signature verification in the \u201csecp256r1\u201d elliptic curve.\n    ///      See https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md.\n    address private constant VERIFIER = address(0x100);\n\n    /// @dev The expected type (hash) in the client data JSON when verifying assertion signatures.\n    ///      See https://www.w3.org/TR/webauthn-2/#dom-collectedclientdata-type\n    bytes32 private constant EXPECTED_TYPE_HASH = keccak256('\"type\":\"webauthn.get\"');\n\n    ///\n    /// @notice Verifies a Webauthn Authentication Assertion as described\n    /// in https://www.w3.org/TR/webauthn-2/#sctn-verifying-assertion.\n    ///\n    /// @dev We do not verify all the steps as described in the specification, only ones relevant to our context.\n    ///      Please carefully read through this list before usage.\n    ///\n    ///      Specifically, we do verify the following:\n    ///         - Verify that authenticatorData (which comes from the authenticator, such as iCloud Keychain) indicates\n    ///           a well-formed assertion with the user present bit set. If `requireUV` is set, checks that the authenticator\n    ///           enforced user verification. User verification should be required if, and only if, options.userVerification\n    ///           is set to required in the request.\n    ///         - Verifies that the client JSON is of type \"webauthn.get\", i.e. the client was responding to a request to\n    ///           assert authentication.\n    ///         - Verifies that the client JSON contains the requested challenge.\n    ///         - Verifies that (r, s) constitute a valid signature over both the authenicatorData and client JSON, for public\n    ///            key (x, y).\n    ///\n    ///      We make some assumptions about the particular use case of this verifier, so we do NOT verify the following:\n    ///         - Does NOT verify that the origin in the `clientDataJSON` matches the Relying Party's origin: tt is considered\n    ///           the authenticator's responsibility to ensure that the user is interacting with the correct RP. This is\n    ///           enforced by most high quality authenticators properly, particularly the iCloud Keychain and Google Password\n    ///           Manager were tested.\n    ///         - Does NOT verify That `topOrigin` in `clientDataJSON` is well-formed: We assume it would never be present, i.e.\n    ///           the credentials are never used in a cross-origin/iframe context. The website/app set up should disallow\n    ///           cross-origin usage of the credentials. This is the default behaviour for created credentials in common settings.\n    ///         - Does NOT verify that the `rpIdHash` in `authenticatorData` is the SHA-256 hash of the RP ID expected by the Relying\n    ///           Party: this means that we rely on the authenticator to properly enforce credentials to be used only by the correct RP.\n    ///           This is generally enforced with features like Apple App Site Association and Google Asset Links. To protect from\n    ///           edge cases in which a previously-linked RP ID is removed from the authorised RP IDs, we recommend that messages\n    ///           signed by the authenticator include some expiry mechanism.\n    ///         - Does NOT verify the credential backup state: this assumes the credential backup state is NOT used as part of Relying\n    ///           Party business logic or policy.\n    ///         - Does NOT verify the values of the client extension outputs: this assumes that the Relying Party does not use client\n    ///           extension outputs.\n    ///         - Does NOT verify the signature counter: signature counters are intended to enable risk scoring for the Relying Party.\n    ///           This assumes risk scoring is not used as part of Relying Party business logic or policy.\n    ///         - Does NOT verify the attestation object: this assumes that response.attestationObject is NOT present in the response,\n    ///           i.e. the RP does not intend to verify an attestation.\n    ///\n    /// @param challenge    The challenge that was provided by the relying party.\n    /// @param requireUV    A boolean indicating whether user verification is required.\n    /// @param webAuthnAuth The `WebAuthnAuth` struct.\n    /// @param x            The x coordinate of the public key.\n    /// @param y            The y coordinate of the public key.\n    ///\n    /// @return `true` if the authentication assertion passed validation, else `false`.\n    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    }\n}"
}