Skip to content
Verified contractPartialApache-2.0

VerifierHelper

Address0x3e4e95454d9d5bee731ee679e696929dc3b3b417
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
Apache-2.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,429,244
Creation transaction
0x614f862e18…fb944a8db3
Libraries
lib/zkpassport-packages/packages/registry-contracts/src/VerifierHelper.sol:InputsExtractor0x9bba…254f4e

lib/zkpassport-packages/packages/registry-contracts/src/VerifierHelper.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

import {RootRegistry} from "./RootRegistry.sol";
import {DateUtils} from "./lib/DateUtils.sol";
import {StringUtils} from "./lib/StringUtils.sol";
import {InputsExtractor} from "./lib/InputsExtractor.sol";
import {SECONDS_BETWEEN_1900_AND_1970, PublicInput, AppAttest, RegistryID} from "./lib/Constants.sol";
import {VerificationMethods} from "./lib/VerificationMethods.sol";
import {AttestationRevocation} from "./lib/AttestedId.sol";
import {ProofType, DisclosedData, BoundData, FaceMatchMode, Environment, OS, NullifierType} from "./lib/Types.sol";

contract VerifierHelper {
    RootRegistry public immutable rootRegistry;

    constructor(RootRegistry _rootRegistry) {
        require(address(_rootRegistry) != address(0), "Root registry cannot be zero address");
        rootRegistry = _rootRegistry;
    }

    /**
     * @notice Gets the data disclosed by the proof
     * @param committedInputs The committed inputs
     * @param isIDCard Whether the proof is an ID card
     * @return disclosedData The data disclosed by the proof
     */
    function getDisclosedData(bytes calldata committedInputs, bool isIDCard)
        external
        pure
        returns (DisclosedData memory disclosedData)
    {
        (, bytes memory discloseBytes) = InputsExtractor.getDiscloseProofInputs(committedInputs);
        require(discloseBytes[0] == 0 || isIDCard == (discloseBytes[0] != "P"), "Document type does not match isIDCard");
        disclosedData = InputsExtractor.getDisclosedData(discloseBytes, isIDCard);
    }

    /**
     * @notice Checks if the age is above or equal to the given age
     * @param minAge The age must be above or equal to this age
     * @param committedInputs The committed inputs
     * @return True if the age is above or equal to the given age, false otherwise
     */
    function isAgeAboveOrEqual(uint8 minAge, bytes calldata committedInputs) public pure returns (bool) {
        (uint8 min, uint8 max) = InputsExtractor.getAgeProofInputs(committedInputs);
        require(max == 0, "The proof upper bound must be 0, please use isAgeBetween instead");
        return minAge == min;
    }

    /**
     * @notice Checks if the age is above the given age
     * @param minAge The age must be above this age
     * @param committedInputs The committed inputs
     * @return True if the age is above the given age, false otherwise
     */
    function isAgeAbove(uint8 minAge, bytes calldata committedInputs) public pure returns (bool) {
        return isAgeAboveOrEqual(minAge + 1, committedInputs);
    }

    /**
     * @notice Checks if the age is in the given range
     * @param minAge The age must be greater than or equal to this age
     * @param maxAge The age must be less than or equal to this age
     * @param committedInputs The committed inputs
     * @return True if the age is in the given range, false otherwise
     */
    function isAgeBetween(uint8 minAge, uint8 maxAge, bytes calldata committedInputs) public pure returns (bool) {
        (uint8 min, uint8 max) = InputsExtractor.getAgeProofInputs(committedInputs);
        require(minAge <= maxAge, "Min age must be less than or equal to max age");
        require(min != 0, "The proof lower bound must be non-zero, please use isAgeBelowOrEqual instead");
        require(max != 0, "The proof upper bound must be non-zero, please use isAgeAboveOrEqual instead");
        return minAge == min && maxAge == max;
    }

    /**
     * @notice Checks if the age is below or equal to the given age
     * @param maxAge The age must be below or equal to this age
     * @param committedInputs The committed inputs
     * @return True if the age is below or equal to the given age, false otherwise
     */
    function isAgeBelowOrEqual(uint8 maxAge, bytes calldata committedInputs) public pure returns (bool) {
        (uint8 min, uint8 max) = InputsExtractor.getAgeProofInputs(committedInputs);
        require(min == 0, "The proof lower bound must be 0, please use isAgeBetween instead");
        return maxAge == max;
    }

    /**
     * @notice Checks if the age is below the given age
     * @param maxAge The age must be below this age
     * @param committedInputs The committed inputs
     * @return True if the age is below the given age, false otherwise
     */
    function isAgeBelow(uint8 maxAge, bytes calldata committedInputs) public pure returns (bool) {
        require(maxAge > 0, "Max age must be greater than 0");
        return isAgeBelowOrEqual(maxAge - 1, committedInputs);
    }

    /**
     * @notice Checks if the age is equal to the given age
     * @param age The age must be equal to this age
     * @param committedInputs The committed inputs
     * @return True if the age is equal to the given age, false otherwise
     */
    function isAgeEqual(uint8 age, bytes calldata committedInputs) public pure returns (bool) {
        return isAgeBetween(age, age, committedInputs);
    }

    function _isDateAfterOrEqual(uint256 minDate, ProofType proofType, bytes calldata committedInputs)
        private
        pure
        returns (bool)
    {
        (uint256 min, uint256 max) = InputsExtractor.getDateProofInputs(committedInputs, proofType);
        require(proofType == ProofType.BIRTHDATE || proofType == ProofType.EXPIRY_DATE, "Invalid proof type");
        if (proofType == ProofType.BIRTHDATE) {
            require(max == 0, "The proof upper bound must be 0, please use isBirthdateBetween instead");
            // Birthdate comparison dates use 1900 as the starting epoch so the proof can take in value
            // prior to 1970, so we need to subtract the difference between 1900 and 1970 (starting UNIX epoch)
            return minDate == min - SECONDS_BETWEEN_1900_AND_1970;
        } else {
            require(max == 0, "The proof upper bound must be 0, please use isExpiryDateBetween instead");
            return minDate == min;
        }
    }

    function _isDateBetween(uint256 minDate, uint256 maxDate, ProofType proofType, bytes calldata committedInputs)
        private
        pure
        returns (bool)
    {
        (uint256 min, uint256 max) = InputsExtractor.getDateProofInputs(committedInputs, proofType);
        require(minDate <= maxDate, "Min date must be less than or equal to max date");
        require(proofType == ProofType.BIRTHDATE || proofType == ProofType.EXPIRY_DATE, "Invalid proof type");
        if (proofType == ProofType.BIRTHDATE) {
            require(min != 0, "The proof lower bound must be non-zero, please use isBirthdateBelowOrEqual instead");
            require(max != 0, "The proof upper bound must be non-zero, please use isBirthdateAboveOrEqual instead");
            // Birthdate comparison dates use 1900 as the starting epoch so the proof can take in values
            // prior to 1970, so we need to subtract the difference between 1900 and 1970 (starting UNIX epoch)
            return minDate == min - SECONDS_BETWEEN_1900_AND_1970 && maxDate == max - SECONDS_BETWEEN_1900_AND_1970;
        } else {
            require(min != 0, "The proof lower bound must be non-zero, please use isExpiryDateBelowOrEqual instead");
            require(max != 0, "The proof upper bound must be non-zero, please use isExpiryDateAboveOrEqual instead");
            return minDate == min && maxDate == max;
        }
    }

    function _isDateBeforeOrEqual(uint256 maxDate, ProofType proofType, bytes calldata committedInputs)
        private
        pure
        returns (bool)
    {
        (uint256 min, uint256 max) = InputsExtractor.getDateProofInputs(committedInputs, proofType);
        require(min == 0, "The proof lower bound must be 0, please use _isDateBetween instead");
        require(proofType == ProofType.BIRTHDATE || proofType == ProofType.EXPIRY_DATE, "Invalid proof type");
        if (proofType == ProofType.BIRTHDATE) {
            require(max != 0, "The proof upper bound must be non-zero, please use isBirthdateAboveOrEqual instead");
            // Birthdate comparison dates use 1900 as the starting epoch so the proof can take in value
            // prior to 1970, so we need to subtract the difference between 1900 and 1970 (starting UNIX epoch)
            return maxDate == max - SECONDS_BETWEEN_1900_AND_1970;
        } else {
            require(max != 0, "The proof upper bound must be non-zero, please use isExpiryDateAboveOrEqual instead");
            return maxDate == max;
        }
    }

    /**
     * @notice Checks if the birthdate is after or equal to the given date
     * @param minDate The birthdate must be after or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is after or equal to the given date, false otherwise
     */
    function isBirthdateAfterOrEqual(uint256 minDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateAfterOrEqual(minDate, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the birthdate is after the given date
     * @param minDate The birthdate must be after this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is after the given date, false otherwise
     */
    function isBirthdateAfter(uint256 minDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateAfterOrEqual(minDate + 1 days, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the birthdate is between the given dates
     * @param minDate The birthdate must be after or equal to this date
     * @param maxDate The birthdate must be before or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is between the given dates, false otherwise
     */
    function isBirthdateBetween(uint256 minDate, uint256 maxDate, bytes calldata committedInputs)
        public
        pure
        returns (bool)
    {
        return _isDateBetween(minDate, maxDate, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the birthdate is before or equal to the given date
     * @param maxDate The birthdate must be before or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is before or equal to the given date, false otherwise
     */
    function isBirthdateBeforeOrEqual(uint256 maxDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBeforeOrEqual(maxDate, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the birthdate is before the given date
     * @param maxDate The birthdate must be before this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is before the given date, false otherwise
     */
    function isBirthdateBefore(uint256 maxDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBeforeOrEqual(maxDate - 1 days, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the birthdate is equal to the given date
     * @param date The birthdate must be equal to this date
     * @param committedInputs The committed inputs
     * @return True if the birthdate is equal to the given date, false otherwise
     */
    function isBirthdateEqual(uint256 date, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBetween(date, date, ProofType.BIRTHDATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is after or equal to the given date
     * @param minDate The expiry date must be after or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is after or equal to the given date, false otherwise
     */
    function isExpiryDateAfterOrEqual(uint256 minDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateAfterOrEqual(minDate, ProofType.EXPIRY_DATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is after the given date
     * @param minDate The expiry date must be after this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is after the given date, false otherwise
     */
    function isExpiryDateAfter(uint256 minDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateAfterOrEqual(minDate + 1 days, ProofType.EXPIRY_DATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is between the given dates
     * @param minDate The expiry date must be after or equal to this date
     * @param maxDate The expiry date must be before or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is between the given dates, false otherwise
     */
    function isExpiryDateBetween(uint256 minDate, uint256 maxDate, bytes calldata committedInputs)
        public
        pure
        returns (bool)
    {
        return _isDateBetween(minDate, maxDate, ProofType.EXPIRY_DATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is before or equal to the given date
     * @param maxDate The expiry date must be before or equal to this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is before or equal to the given date, false otherwise
     */
    function isExpiryDateBeforeOrEqual(uint256 maxDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBeforeOrEqual(maxDate, ProofType.EXPIRY_DATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is before the given date
     * @param maxDate The expiry date must be before this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is before the given date, false otherwise
     */
    function isExpiryDateBefore(uint256 maxDate, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBeforeOrEqual(maxDate - 1 days, ProofType.EXPIRY_DATE, committedInputs);
    }

    /**
     * @notice Checks if the expiry date is equal to the given date
     * @param date The expiry date must be equal to this date
     * @param committedInputs The committed inputs
     * @return True if the expiry date is equal to the given date, false otherwise
     */
    function isExpiryDateEqual(uint256 date, bytes calldata committedInputs) public pure returns (bool) {
        return _isDateBetween(date, date, ProofType.EXPIRY_DATE, committedInputs);
    }

    function isCountryInOrOut(string[] memory countryList, ProofType proofType, bytes calldata committedInputs)
        private
        pure
        returns (bool)
    {
        (string[] memory inputCountryList, uint256 inputCountryListLength) =
            InputsExtractor.getCountryProofInputs(committedInputs, proofType);
        if (countryList.length != inputCountryListLength) {
            return false;
        }
        for (uint256 i = 0; i < inputCountryListLength; i++) {
            if (!StringUtils.equals(countryList[i], inputCountryList[i])) {
                return false;
            }
        }
        return true;
    }

    /**
     * @notice Checks if the nationality is in the list of countries
     * @param countryList The list of countries (needs to match exactly the list of countries in the proof)
     * @param committedInputs The committed inputs
     * @return True if the nationality is in the list of countries, false otherwise
     */
    function isNationalityIn(string[] memory countryList, bytes calldata committedInputs) external pure returns (bool) {
        return isCountryInOrOut(countryList, ProofType.NATIONALITY_INCLUSION, committedInputs);
    }

    /**
     * @notice Checks if the issuing country is in the list of countries
     * @param countryList The list of countries (needs to match exactly the list of countries in the proof)
     * @param committedInputs The committed inputs
     * @return True if the issuing country is in the list of countries, false otherwise
     */
    function isIssuingCountryIn(string[] memory countryList, bytes calldata committedInputs)
        external
        pure
        returns (bool)
    {
        return isCountryInOrOut(countryList, ProofType.ISSUING_COUNTRY_INCLUSION, committedInputs);
    }

    /**
     * @notice Checks if the nationality is not in the list of countries
     * @param countryList The list of countries (needs to match exactly the list of countries in the proof)
     * Note: The list of countries must be sorted in alphabetical order
     * @param committedInputs The committed inputs
     * @return True if the nationality is not in the list of countries, false otherwise
     */
    function isNationalityOut(string[] memory countryList, bytes calldata committedInputs)
        external
        pure
        returns (bool)
    {
        return isCountryInOrOut(countryList, ProofType.NATIONALITY_EXCLUSION, committedInputs);
    }

    /**
     * @notice Checks if the issuing country is not in the list of countries
     * @param countryList The list of countries (needs to match exactly the list of countries in the proof)
     * Note: The list of countries must be sorted in alphabetical order
     * @param committedInputs The committed inputs
     * @return True if the issuing country is not in the list of countries, false otherwise
     */
    function isIssuingCountryOut(string[] memory countryList, bytes calldata committedInputs)
        external
        pure
        returns (bool)
    {
        return isCountryInOrOut(countryList, ProofType.ISSUING_COUNTRY_EXCLUSION, committedInputs);
    }

    /**
     * @notice Gets the data bound to the proof
     * @param committedInputs The committed inputs
     * @return boundData The data bound to the proof
     */
    function getBoundData(bytes calldata committedInputs) external pure returns (BoundData memory boundData) {
        bytes memory data = InputsExtractor.getBindProofInputs(committedInputs);
        (boundData.senderAddress, boundData.chainId, boundData.customData) = InputsExtractor.getBoundData(data);
    }

    /**
     * @notice Checks if the sanctions root is valid against the expected sanction list(s)
     * @param currentTimestamp The current timestamp (preferably from the proof rather than the block timestamp).
     * This is used to check the validity of the sanctions root at that specific time.
     * @param isStrict Whether the sanctions check was strict or not
     * @param committedInputs The committed inputs
     * @return True if the sanctions root is valid against the expected sanction list(s), false otherwise
     */
    function isSanctionsRootValid(uint256 currentTimestamp, bool isStrict, bytes calldata committedInputs)
        external
        view
        returns (bool)
    {
        return _isSanctionsRootValid(currentTimestamp, isStrict, committedInputs);
    }

    function _isSanctionsRootValid(uint256 currentTimestamp, bool isStrict, bytes calldata committedInputs)
        internal
        view
        returns (bool)
    {
        (bytes32 proofSanctionsRoot, bool retrievedIsStrict) = InputsExtractor.getSanctionsProofInputs(committedInputs);
        require(isStrict == retrievedIsStrict, "Invalid sanctions check mode");
        return rootRegistry.isRootValid(RegistryID.SANCTIONS, proofSanctionsRoot, currentTimestamp);
    }

    /**
     * @notice Enforces that the proof checks against the expected sanction list(s)
     * @param currentTimestamp The current timestamp (preferably from the proof rather than the block timestamp).
     * This is used to check the validity of the sanctions root at that specific time.
     * @param isStrict Whether the sanctions check was strict or not
     * @param committedInputs The committed inputs
     */
    function enforceSanctionsRoot(uint256 currentTimestamp, bool isStrict, bytes calldata committedInputs)
        external
        view
    {
        bool isValid = _isSanctionsRootValid(currentTimestamp, isStrict, committedInputs);
        require(isValid, "Invalid sanctions registry root");
    }

    /**
     * @notice Checks if the proof is tied to a FaceMatch verification
     * @dev Without a FaceMatch entry, a device attested ID entry (strict mode) is the face match evidence
     * @param faceMatchMode The FaceMatch mode expected to be used in the verification
     * @param os The operating system on which the proof should have been generated (Any (0), iOS (1), Android (2))
     * @param committedInputs The committed inputs
     * @return True if the proof is tied to a valid FaceMatch verification, false otherwise
     */
    function isFaceMatchVerified(FaceMatchMode faceMatchMode, OS os, bytes calldata committedInputs)
        external
        view
        returns (bool)
    {
        (
            bytes32 rootKeyHash,
            Environment environment,
            bytes32 appIdHash,
            bytes32 integrityPublicKeyHash,
            FaceMatchMode retrievedFaceMatchMode,
            bytes32 revocationRoot
        ) = !InputsExtractor.containsProofType(committedInputs, ProofType.FACEMATCH)
            && InputsExtractor.containsProofType(committedInputs, ProofType.ATTESTED_ID)
            ? InputsExtractor.getAttestedIdProofInputs(committedInputs)
            : InputsExtractor.getFacematchProofInputs(committedInputs);
        if (environment != Environment.PRODUCTION || retrievedFaceMatchMode != faceMatchMode) return false;
        bool isIosAppIdHash = appIdHash == AppAttest.IOS_APP_ID_HASH || appIdHash == AppAttest.IOS_APP_CLIP_APP_ID_HASH;
        bool isIos = rootKeyHash == AppAttest.APPLE_ROOT_KEY_HASH && isIosAppIdHash
            && integrityPublicKeyHash == bytes32(0) && revocationRoot == bytes32(0);
        if (isIos) return os == OS.IOS || os == OS.ANY;
        bool isAndroid =
            (rootKeyHash == AppAttest.GOOGLE_RSA_ROOT_KEY_HASH || rootKeyHash == AppAttest.GOOGLE_ECDSA_ROOT_KEY_HASH)
                && appIdHash == AppAttest.ANDROID_APP_ID_HASH
                && integrityPublicKeyHash == AppAttest.ANDROID_INTEGRITY_PUBLIC_KEY_HASH;
        if (!isAndroid || (os != OS.ANDROID && os != OS.ANY)) return false;
        return AttestationRevocation.isRootAccepted(rootRegistry, revocationRoot, block.timestamp);
    }

    /**
     * @notice Gets the timestamp the proof was generated at
     * @param publicInputs The public inputs of the proof
     * @return The timestamp the proof was generated at
     */
    function getProofTimestamp(bytes32[] calldata publicInputs) external pure returns (uint256) {
        return uint256(publicInputs[PublicInput.CURRENT_DATE_INDEX]);
    }

    /**
     * @notice Gets the nullifier type the proof was generated with
     * @param publicInputs The public inputs of the proof
     * @return The nullifier type of the proof
     */
    function getNullifierType(bytes32[] calldata publicInputs) public pure returns (NullifierType) {
        return NullifierType(uint256(publicInputs[publicInputs.length - PublicInput.NULLIFIER_TYPE_OFFSET_FROM_END]));
    }

    /**
     * @notice Enforces that the proof was generated with the expected nullifier type
     * @dev A mock type matches its real counterpart, as mock proofs are only accepted in dev mode
     * @param expectedNullifierType The expected nullifier type
     * @param publicInputs The public inputs of the proof
     */
    function enforceNullifierType(NullifierType expectedNullifierType, bytes32[] calldata publicInputs) external pure {
        require(_realNullifierType(publicInputs) == expectedNullifierType, "Invalid nullifier type");
    }

    function _realNullifierType(bytes32[] calldata publicInputs) private pure returns (NullifierType) {
        NullifierType nullifierType = getNullifierType(publicInputs);
        if (nullifierType == NullifierType.SALTED_MOCK_NULLIFIER) {
            return NullifierType.SALTED_NULLIFIER;
        }
        if (nullifierType == NullifierType.NON_SALTED_MOCK_NULLIFIER) {
            // Mock IDs keep their mock type even when the nullifier is hidden
            bool hasNullifier =
                publicInputs[publicInputs.length - PublicInput.SCOPED_NULLIFIER_OFFSET_FROM_END] != bytes32(0);
            return hasNullifier ? NullifierType.NON_SALTED_NULLIFIER : NullifierType.NONE_NULLIFIER;
        }
        return nullifierType;
    }

    /**
     * @notice Gets the verification method the ID was verified with, see lib/VerificationMethods.sol
     * @param publicInputs The public inputs of the proof
     * @return The verification method
     */
    function getVerificationMethod(bytes32[] calldata publicInputs) public pure returns (uint256) {
        return uint256(publicInputs[publicInputs.length - PublicInput.VERIFICATION_METHOD_OFFSET_FROM_END]);
    }

    /**
     * @notice Whether the proof's verification method is in a list of accepted ones
     * @param allowedVerificationMethods Exact schemes (e.g. 201) and/or whole tiers (an entry below 100,
     *        e.g. 1 for every issuer-signed scheme), so [1, 201] accepts tier 1 and Android camera reads.
     *        Empty means tier 1 only.
     * @param publicInputs The public inputs of the proof
     * @return True if accepted, false otherwise
     */
    function isVerificationMethodAllowed(uint256[] memory allowedVerificationMethods, bytes32[] calldata publicInputs)
        public
        pure
        returns (bool)
    {
        return VerificationMethods.isAllowed(getVerificationMethod(publicInputs), allowedVerificationMethods);
    }

    /**
     * @notice Reverts unless the proof's verification method is accepted, see isVerificationMethodAllowed
     * @param allowedVerificationMethods Exact schemes and/or whole tiers; empty means tier 1 only
     * @param publicInputs The public inputs of the proof
     */
    function enforceVerificationMethod(uint256[] memory allowedVerificationMethods, bytes32[] calldata publicInputs)
        external
        pure
    {
        require(
            isVerificationMethodAllowed(allowedVerificationMethods, publicInputs), "Verification method not allowed"
        );
    }

    /**
     * @notice Verifies that the proof was generated for the given scope (domain) and subscope (service scope)
     * @param publicInputs The public inputs of the proof
     * @param scope The scope (domain) to check against
     * @param subscope The subscope (service scope) to check against
     * @return True if valid, false otherwise
     */
    function verifyScopes(bytes32[] calldata publicInputs, string calldata scope, string calldata subscope)
        external
        pure
        returns (bool)
    {
        // One byte is dropped at the end
        // What we call scope internally is derived from the domain
        bytes32 scopeHash = StringUtils.isEmpty(scope) ? bytes32(0) : sha256(abi.encodePacked(scope)) >> 8;
        // What we call the subscope internally is the service scope specified manually in the SDK
        bytes32 subscopeHash = StringUtils.isEmpty(subscope) ? bytes32(0) : sha256(abi.encodePacked(subscope)) >> 8;
        return
            publicInputs[PublicInput.SCOPE_INDEX] == scopeHash
                && publicInputs[PublicInput.SUBSCOPE_INDEX] == subscopeHash;
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/IRegistryInstance.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

/**
 * @title IRegistryInstance
 * @dev Interface for a registry instance
 */
interface IRegistryInstance {
    function latestRoot() external view returns (bytes32);
    function historicalRoots(bytes32 root)
        external
        view
        returns (
            uint256 validFrom,
            uint256 validTo,
            bool revoked,
            uint256 leaves,
            bytes32 cid,
            bytes32 metadata1,
            bytes32 metadata2,
            bytes32 metadata3
        );
    function rootCount() external view returns (uint256);
    function rootByIndex(uint256 index) external view returns (bytes32);
    function indexByRoot(bytes32 root) external view returns (uint256);
    function rootValidationMode() external view returns (RootValidationMode);
    function isRootValid(bytes32 root, uint256 timestamp) external view returns (bool);
    function isRootValidAtTimestamp(bytes32 root, uint256 timestamp) external view returns (bool);
}

// Root validation modes
enum RootValidationMode {
    // Is root the latest root?
    LATEST_ONLY,
    // Is root either the latest or previous root?
    LATEST_AND_PREVIOUS,
    // Is root valid at timestamp T? i.e. validFrom <= T <= validTo
    VALID_AT_TIMESTAMP,
    // Is root valid within the last W seconds from timestamp T? i.e. validFrom <= T AND T-W <= validTo
    VALID_WITHIN_WINDOW
}

lib/zkpassport-packages/packages/registry-contracts/src/RootRegistry.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

import {IRegistryInstance} from "./IRegistryInstance.sol";

/**
 * @title RootRegistry
 * @dev ZKPassport Root Registry
 */
contract RootRegistry {
    address public admin;
    address public guardian;
    bool public paused;

    // Registry mapping: registry identifier => registry contract address
    mapping(bytes32 registryId => IRegistryInstance instance) public registries;

    // Counter for the number of active registries
    uint256 public registryCount;

    // Config mapping: config key => config value
    mapping(bytes32 key => bytes32 value) public config;

    // Events
    event RootRegistryDeployed(address indexed admin, address indexed guardian);
    event AdminUpdated(address indexed oldAdmin, address indexed newAdmin);
    event GuardianUpdated(address indexed oldGuardian, address indexed newGuardian);
    event RegistryAdded(bytes32 indexed registryId, address indexed registryAddress);
    event RegistryUpdated(bytes32 indexed registryId, address indexed oldAddress, address indexed newAddress);
    event RegistryRemoved(bytes32 indexed registryId, address indexed registryAddress);
    event PausedStatusChanged(bool paused);
    event ConfigUpdated(bytes32 indexed key, bytes32 oldValue, bytes32 newValue);

    /**
     * @dev Constructor
     */
    constructor(address _admin, address _guardian) {
        require(_admin != address(0), "Admin cannot be zero address");
        admin = _admin;
        guardian = _guardian;
        emit RootRegistryDeployed(admin, guardian);
    }

    modifier onlyAdmin() {
        require(msg.sender == admin, "Not authorized: admin only");
        _;
    }

    modifier onlyAdminOrGuardian() {
        require(msg.sender == admin || msg.sender == guardian, "Not authorized: admin or guardian only");
        _;
    }

    /**
     * @dev Add a new registry
     * @param registryId The registry identifier
     * @param registryAddress The registry address
     */
    function addRegistry(bytes32 registryId, IRegistryInstance registryAddress) external onlyAdmin {
        require(address(registryAddress) != address(0), "Registry address cannot be zero address");
        require(address(registries[registryId]) == address(0), "Registry already exists");
        registryCount++;
        registries[registryId] = registryAddress;
        emit RegistryAdded(registryId, address(registryAddress));
    }

    /**
     * @dev Update an existing registry
     * @param registryId The registry identifier
     * @param newAddress The new registry address
     */
    function updateRegistry(bytes32 registryId, IRegistryInstance newAddress) external onlyAdmin {
        require(address(newAddress) != address(0), "Registry address cannot be zero address");
        IRegistryInstance oldAddress = registries[registryId];
        require(address(oldAddress) != address(0), "Registry does not exist");
        registries[registryId] = newAddress;
        emit RegistryUpdated(registryId, address(oldAddress), address(newAddress));
    }

    /**
     * @dev Remove an existing registry
     * @param registryId The registry identifier
     */
    function removeRegistry(bytes32 registryId) external onlyAdmin {
        IRegistryInstance registryAddress = registries[registryId];
        require(address(registryAddress) != address(0), "Registry does not exist");
        registryCount--;
        delete registries[registryId];
        emit RegistryRemoved(registryId, address(registryAddress));
    }

    /**
     * @dev Transfer the admin role to a new address
     * @param newAdmin The new admin address
     */
    function transferAdmin(address newAdmin) external onlyAdmin {
        require(newAdmin != address(0), "Admin cannot be zero address");
        address oldAdmin = admin;
        admin = newAdmin;
        emit AdminUpdated(oldAdmin, newAdmin);
    }

    /**
     * @dev Set the guardian address
     * @param newGuardian The new guardian address
     */
    function setGuardian(address newGuardian) external onlyAdmin {
        address oldGuardian = guardian;
        guardian = newGuardian;
        emit GuardianUpdated(oldGuardian, newGuardian);
    }

    /**
     * @dev Update a config value
     * @param key The config key
     * @param value The config value
     */
    function updateConfig(bytes32 key, bytes32 value) external onlyAdmin {
        bytes32 oldValue = config[key];
        config[key] = value;
        emit ConfigUpdated(key, oldValue, value);
    }

    /**
     * @dev Pause the root registry
     * @notice Only admin or guardian can pause the root registry
     */
    function pause() external onlyAdminOrGuardian {
        paused = true;
        emit PausedStatusChanged(true);
    }

    /**
     * @dev Unpause the root registry
     * @notice Only admin can unpause the root registry
     */
    function unpause() external onlyAdmin {
        paused = false;
        emit PausedStatusChanged(false);
    }

    /**
     * @dev Get the latest root of a specific registry
     * @param registryId The registry identifier
     * @return root The latest root, or bytes32(0) if registry doesn't exist or call fails
     */
    function latestRoot(bytes32 registryId) external view returns (bytes32) {
        // Return bytes32(0) if registry with this identifier doesn't exist
        if (address(registries[registryId]) == address(0)) return bytes32(0);

        // Return the latest root from the registry instance
        try IRegistryInstance(registries[registryId]).latestRoot() returns (bytes32 root) {
            return root;
        } catch {
            return bytes32(0);
        }
    }

    /**
     * @dev Check if a root is valid for a specific registry
     * @param registryId The registry identifier
     * @param root The root to check
     * @param timestamp The timestamp to check validity for (how this is validated depends on the registry's validation mode)
     * @return valid True if the root is valid
     */
    function isRootValid(bytes32 registryId, bytes32 root, uint256 timestamp) external view returns (bool) {
        // Return false if contract is paused
        if (paused) return false;

        // Return false if registry with this identifier doesn't exist
        if (address(registries[registryId]) == address(0)) return false;

        // Call isRootValid on registry instance
        try IRegistryInstance(registries[registryId]).isRootValid(root, timestamp) returns (bool valid) {
            return valid;
        } catch {
            return false;
        }
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/AttestedId.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

import {AppAttest, RegistryID} from "./Constants.sol";
import {RootRegistry} from "../RootRegistry.sol";
import {VerificationMethod} from "./VerificationMethods.sol";
import {Environment, FaceMatchMode} from "./Types.sol";

/**
 * @notice The circuit takes the attestation root key as an input, so a device attested (2xx)
 *         credential is only sound if the verifier pins it, along with the app and the face match mode
 */
library AttestedId {
    function isValid(
        uint256 verificationMethod,
        bytes32 rootKeyHash,
        Environment environment,
        bytes32 appIdHash,
        bytes32 integrityPublicKeyHash,
        FaceMatchMode mode
    ) internal pure returns (bool) {
        if (environment != Environment.PRODUCTION || mode != FaceMatchMode.STRICT) {
            return false;
        }
        if (verificationMethod == VerificationMethod.ATTESTED_CAPTURE_IOS) {
            return rootKeyHash == AppAttest.APPLE_ROOT_KEY_HASH && appIdHash == AppAttest.IOS_APP_ID_HASH
                && integrityPublicKeyHash == bytes32(0);
        }
        if (verificationMethod == VerificationMethod.ATTESTED_CAPTURE_ANDROID) {
            return (rootKeyHash == AppAttest.GOOGLE_RSA_ROOT_KEY_HASH
                    || rootKeyHash == AppAttest.GOOGLE_ECDSA_ROOT_KEY_HASH)
                && appIdHash == AppAttest.ANDROID_APP_ID_HASH
                && integrityPublicKeyHash == AppAttest.ANDROID_INTEGRITY_PUBLIC_KEY_HASH;
        }
        return false;
    }
}

/// @notice The face match circuit takes its root key as an input, so the verifier pins the root key and the app
library FaceMatch {
    function isGenuine(bytes32 rootKeyHash, Environment environment, bytes32 appIdHash, bytes32 integrityPublicKeyHash)
        internal
        pure
        returns (bool)
    {
        if (environment != Environment.PRODUCTION) {
            return false;
        }
        if (rootKeyHash == AppAttest.APPLE_ROOT_KEY_HASH) {
            return (appIdHash == AppAttest.IOS_APP_ID_HASH || appIdHash == AppAttest.IOS_APP_CLIP_APP_ID_HASH)
                && integrityPublicKeyHash == bytes32(0);
        }
        if (rootKeyHash == AppAttest.GOOGLE_RSA_ROOT_KEY_HASH || rootKeyHash == AppAttest.GOOGLE_ECDSA_ROOT_KEY_HASH) {
            return appIdHash == AppAttest.ANDROID_APP_ID_HASH
                && integrityPublicKeyHash == AppAttest.ANDROID_INTEGRITY_PUBLIC_KEY_HASH;
        }
        return false;
    }
}

/**
 * @notice An Android attestation chain is checked in the circuit against a tree of revoked certificate serials,
 *         whose root the verifier must find in the attestation revocation registry. The empty tree's root is
 *         accepted only while that registry has no root, so it stops being accepted once the first one is published.
 */
library AttestationRevocation {
    function isRootAccepted(RootRegistry rootRegistry, bytes32 revocationRoot, uint256 timestamp)
        internal
        view
        returns (bool)
    {
        if (revocationRoot == AppAttest.EMPTY_REVOCATION_ROOT) {
            return rootRegistry.latestRoot(RegistryID.ATTESTATION_REVOCATION) == bytes32(0);
        }
        return rootRegistry.isRootValid(RegistryID.ATTESTATION_REVOCATION, revocationRoot, timestamp);
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/Constants.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

uint256 constant SECONDS_BETWEEN_1900_AND_1970 = 2208988800;
uint256 constant COUNTRY_LIST_LENGTH = 200;
uint256 constant BOUND_DATA_LENGTH = 509;
uint256 constant TIMESTAMP_LENGTH = 8;

// Registry IDs
library RegistryID {
    bytes32 constant CERTIFICATE = bytes32(0x0000000000000000000000000000000000000000000000000000000000000001);
    bytes32 constant CIRCUIT = bytes32(0x0000000000000000000000000000000000000000000000000000000000000002);
    bytes32 constant SANCTIONS = bytes32(0x0000000000000000000000000000000000000000000000000000000000000003);
    bytes32 constant ATTESTATION_REVOCATION =
        bytes32(0x0000000000000000000000000000000000000000000000000000000000000004);
}

// The lengths of the preimages of the `param_commitments` of the various disclosure circuits.
// Note: this is excluding the 3 bytes for the proof type and length
library CommittedInputLen {
    uint256 constant COMPARE_AGE = 2;
    uint256 constant COMPARE_BIRTHDATE = 16;
    uint256 constant COMPARE_EXPIRY = 16;
    uint256 constant DISCLOSE_BYTES = 180;
    uint256 constant INCL_ISSUING_COUNTRY = 600;
    uint256 constant EXCL_ISSUING_COUNTRY = 600;
    uint256 constant INCL_NATIONALITY = 600;
    uint256 constant EXCL_NATIONALITY = 600;
    uint256 constant BIND = 509;
    uint256 constant SANCTIONS = 33;
    uint256 constant FACEMATCH = 130;
    uint256 constant ATTESTED_ID = 130;
}

// Gather all the public input indices in one place
library PublicInput {
    uint256 constant CERTIFICATE_REGISTRY_ROOT_INDEX = 0;
    uint256 constant CIRCUIT_REGISTRY_ROOT_INDEX = 1;
    uint256 constant CURRENT_DATE_INDEX = 2;
    uint256 constant SCOPE_INDEX = 3;
    uint256 constant SUBSCOPE_INDEX = 4;
    uint256 constant PARAM_COMMITMENTS_INDEX = 5;
    // The length of the public inputs excluding the param commitments
    uint256 constant PUBLIC_INPUTS_EXCLUDING_PARAM_COMMITMENTS_LENGTH = 9;
    // The trailing public inputs, counted from the end
    uint256 constant NULLIFIER_TYPE_OFFSET_FROM_END = 4;
    uint256 constant SCOPED_NULLIFIER_OFFSET_FROM_END = 3;
    uint256 constant OPRF_PK_HASH_OFFSET_FROM_END = 2;
    uint256 constant VERIFICATION_METHOD_OFFSET_FROM_END = 1;
}

// Gather all the MRZ indices in one place
library MRZIndex {
    // Index for the country of issuance of the passport
    uint256 constant PASSPORT_MRZ_ISSUING_COUNTRY_INDEX = 2;
    // Index for the three letter code of the country of citizenship
    // Note that the first three letter code (index 2) in the MRZ is the country of issuance
    // not citizenship. It is important to keep in mind for residence permits
    // where the issuing country differs from the citizenship country
    uint256 constant PASSPORT_MRZ_NATIONALITY_INDEX = 54;
    // Index for the gender of the passport holder (M, F or < if unspecified)
    uint256 constant PASSPORT_MRZ_GENDER_INDEX = 64;
    // Index for the date of expiry (YYMMDD)
    uint256 constant PASSPORT_MRZ_EXPIRY_DATE_INDEX = 65;
    // Index for the date of birth (YYMMDD) in TD1 (i.e. passport) MRZ
    uint256 constant PASSPORT_MRZ_BIRTHDATE_INDEX = 57;
    // Index for the document number in the MRZ
    uint256 constant PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX = 44;
    // Index for the document type in the MRZ
    uint256 constant PASSPORT_MRZ_DOCUMENT_TYPE_INDEX = 0;
    // Index for the name of the passport holder
    uint256 constant PASSPORT_MRZ_NAME_INDEX = 5;

    // Index for the country of issuance of the ID card
    uint256 constant ID_CARD_MRZ_ISSUING_COUNTRY_INDEX = 2;
    // Note that the first three letter code (index 2) in the MRZ is the country of issuance
    // not citizenship. It is important to keep in mind for residence permits
    // where the issuing country differs from the citizenship country
    uint256 constant ID_CARD_MRZ_NATIONALITY_INDEX = 45;
    // Index for the gender of the passport holder (M, F or < if unspecified)
    uint256 constant ID_CARD_MRZ_GENDER_INDEX = 37;
    // Index for the date of expiry (YYMMDD)
    uint256 constant ID_CARD_MRZ_EXPIRY_DATE_INDEX = 38;
    // Index for the date of birth (YYMMDD) in TD3 (i.e. ID cards) MRZ
    uint256 constant ID_CARD_MRZ_BIRTHDATE_INDEX = 30;
    // Index for the document number in the MRZ
    uint256 constant ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX = 5;
    // Index for the document type in the MRZ
    uint256 constant ID_CARD_MRZ_DOCUMENT_TYPE_INDEX = 0;
    // Index for the name of the passport holder
    uint256 constant ID_CARD_MRZ_NAME_INDEX = 60;
}

// Gather all the MRZ field lengths in one place
library MRZLength {
    uint256 constant PASSPORT_MRZ_LENGTH = 88;
    uint256 constant ID_CARD_MRZ_LENGTH = 90;
    uint256 constant MRZ_MAX_LENGTH = 90;
    uint256 constant PASSPORT_MRZ_ISSUING_COUNTRY_LENGTH = 3;
    uint256 constant ID_CARD_MRZ_ISSUING_COUNTRY_LENGTH = 3;
    uint256 constant PASSPORT_MRZ_NATIONALITY_LENGTH = 3;
    uint256 constant ID_CARD_MRZ_NATIONALITY_LENGTH = 3;
    uint256 constant PASSPORT_MRZ_GENDER_LENGTH = 1;
    uint256 constant ID_CARD_MRZ_GENDER_LENGTH = 1;
    uint256 constant PASSPORT_MRZ_BIRTHDATE_LENGTH = 6;
    uint256 constant ID_CARD_MRZ_BIRTHDATE_LENGTH = 6;
    uint256 constant PASSPORT_MRZ_EXPIRY_DATE_LENGTH = 6;
    uint256 constant ID_CARD_MRZ_EXPIRY_DATE_LENGTH = 6;
    uint256 constant PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH = 9;
    uint256 constant ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH = 9;
    uint256 constant PASSPORT_MRZ_DOCUMENT_TYPE_LENGTH = 2;
    uint256 constant ID_CARD_MRZ_DOCUMENT_TYPE_LENGTH = 2;
    uint256 constant PASSPORT_MRZ_NAME_LENGTH = 39;
    uint256 constant ID_CARD_MRZ_NAME_LENGTH = 30;
    uint256 constant PASSPORT_MRZ_YEAR_OF_BIRTH_LENGTH = 2;
    uint256 constant ID_CARD_MRZ_YEAR_OF_BIRTH_LENGTH = 2;
}

library AppAttest {
    // ZKPassport iOS App ID hash
    // Little-endian packed and poseidon2 hash of `YL5MS3Z639.app.zkpassport.zkpassport`
    bytes32 constant IOS_APP_ID_HASH = 0x1fa73686cf510f8f85757b0602de0dd72a13e68ae2092462be8b72662e7f179b;
    // ZKPassport iOS App Clip App ID hash
    // Little-endian packed and poseidon2 hash of `YL5MS3Z639.app.zkpassport.zkpassport.clip`
    bytes32 constant IOS_APP_CLIP_APP_ID_HASH = 0x1409355f7733451c37093c8aac68611b102c0f270c9961d74ef6cfa6f888d3f0;
    // ZKPassport Android App ID hash
    // Little-endian packed and poseidon2 hash of `app.zkpassport.zkpassport`
    bytes32 constant ANDROID_APP_ID_HASH = 0x24d9929b248be7eeecaa98e105c034a50539610f3fdd4cb9c8983ef4100d615d;
    // The hash of Apple's root certificate public key
    bytes32 constant APPLE_ROOT_KEY_HASH = 0x2532418a107c5306fa8308c22255792cf77e4a290cbce8a840a642a3e591340b;
    // The hash of Google's RSA root certificate public key
    bytes32 constant GOOGLE_RSA_ROOT_KEY_HASH = 0x16700a2d9168a194fc85f237af5829b5a2be05b8ae8ac4879ada34cf54a9c211;
    // The hash of Google's ECDSA (P384) root certificate public key
    bytes32 constant GOOGLE_ECDSA_ROOT_KEY_HASH = 0x0e1889bec6c1d686abcf08360ff404f803ab345881ea8cba6aad33b7f7f7ffe0;
    // Root of the Android attestation revocation tree with no revoked serials, accepted only while
    // the attestation revocation registry has no root
    bytes32 constant EMPTY_REVOCATION_ROOT = 0x23157e6435e936c4698498358363acb2a9a811908c4806e1087677338e1c5525;
    // The hash of the Android integrity public key
    bytes32 constant ANDROID_INTEGRITY_PUBLIC_KEY_HASH = 0x12e3dc7cc8fec0205b51ff21825630865028f3be5bc64a6eec9ee5e71221319f;
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/DateUtils.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

/**
 * @title DateUtils
 * @dev Utility functions for date operations
 */
library DateUtils {
    /**
     * @dev Validates if a date is within a validity period
     * @param timestamp The timestamp in seconds since the Unix epoch
     * @param validityPeriodInSeconds The validity period in seconds
     * @return True if the date is valid and within the validity period
     */
    function isDateValid(uint256 timestamp, uint256 validityPeriodInSeconds) internal view returns (bool) {
        uint256 validityPeriodTimestamp = timestamp + validityPeriodInSeconds;
        return block.timestamp >= timestamp && validityPeriodTimestamp > timestamp
            && validityPeriodTimestamp > block.timestamp;
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/InputsExtractor.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

import {
    MRZIndex,
    MRZLength,
    CommittedInputLen,
    COUNTRY_LIST_LENGTH,
    BOUND_DATA_LENGTH,
    TIMESTAMP_LENGTH
} from "./Constants.sol";
import {DisclosedData, ProofType, FaceMatchMode, Environment, BoundDataIdentifier} from "./Types.sol";

/**
 * @title InputsExtractor
 * @dev Utility functions for extracting inputs from committed inputs
 */
library InputsExtractor {
    function getDisclosedData(bytes calldata discloseBytes, bool isIDCard)
        public
        pure
        returns (DisclosedData memory disclosedData)
    {
        if (!isIDCard) {
            disclosedData.name = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_NAME_INDEX:MRZIndex.PASSPORT_MRZ_NAME_INDEX
                            + MRZLength.PASSPORT_MRZ_NAME_LENGTH
                ]
            );
            disclosedData.issuingCountry = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_ISSUING_COUNTRY_INDEX:MRZIndex.PASSPORT_MRZ_ISSUING_COUNTRY_INDEX
                            + MRZLength.PASSPORT_MRZ_ISSUING_COUNTRY_LENGTH
                ]
            );
            disclosedData.nationality = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_NATIONALITY_INDEX:MRZIndex.PASSPORT_MRZ_NATIONALITY_INDEX
                            + MRZLength.PASSPORT_MRZ_NATIONALITY_LENGTH
                ]
            );
            disclosedData.gender = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_GENDER_INDEX:MRZIndex.PASSPORT_MRZ_GENDER_INDEX
                            + MRZLength.PASSPORT_MRZ_GENDER_LENGTH
                ]
            );
            disclosedData.birthDate = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_BIRTHDATE_INDEX:MRZIndex.PASSPORT_MRZ_BIRTHDATE_INDEX
                            + MRZLength.PASSPORT_MRZ_BIRTHDATE_LENGTH
                ]
            );
            disclosedData.expiryDate = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_EXPIRY_DATE_INDEX:MRZIndex.PASSPORT_MRZ_EXPIRY_DATE_INDEX
                            + MRZLength.PASSPORT_MRZ_EXPIRY_DATE_LENGTH
                ]
            );
            disclosedData.documentNumber = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX:MRZIndex.PASSPORT_MRZ_DOCUMENT_NUMBER_INDEX
                            + MRZLength.PASSPORT_MRZ_DOCUMENT_NUMBER_LENGTH
                ]
            );
            disclosedData.documentType = string(
                discloseBytes[MRZIndex.PASSPORT_MRZ_DOCUMENT_TYPE_INDEX:MRZIndex.PASSPORT_MRZ_DOCUMENT_TYPE_INDEX
                            + MRZLength.PASSPORT_MRZ_DOCUMENT_TYPE_LENGTH
                ]
            );
        } else {
            disclosedData.name = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_NAME_INDEX:MRZIndex.ID_CARD_MRZ_NAME_INDEX
                            + MRZLength.ID_CARD_MRZ_NAME_LENGTH
                ]
            );
            disclosedData.issuingCountry = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_ISSUING_COUNTRY_INDEX:MRZIndex.ID_CARD_MRZ_ISSUING_COUNTRY_INDEX
                            + MRZLength.ID_CARD_MRZ_ISSUING_COUNTRY_LENGTH
                ]
            );
            disclosedData.nationality = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_NATIONALITY_INDEX:MRZIndex.ID_CARD_MRZ_NATIONALITY_INDEX
                            + MRZLength.ID_CARD_MRZ_NATIONALITY_LENGTH
                ]
            );
            disclosedData.gender = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_GENDER_INDEX:MRZIndex.ID_CARD_MRZ_GENDER_INDEX
                            + MRZLength.ID_CARD_MRZ_GENDER_LENGTH
                ]
            );
            disclosedData.birthDate = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_BIRTHDATE_INDEX:MRZIndex.ID_CARD_MRZ_BIRTHDATE_INDEX
                            + MRZLength.ID_CARD_MRZ_BIRTHDATE_LENGTH
                ]
            );
            disclosedData.expiryDate = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_EXPIRY_DATE_INDEX:MRZIndex.ID_CARD_MRZ_EXPIRY_DATE_INDEX
                            + MRZLength.ID_CARD_MRZ_EXPIRY_DATE_LENGTH
                ]
            );
            disclosedData.documentNumber = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX:MRZIndex.ID_CARD_MRZ_DOCUMENT_NUMBER_INDEX
                            + MRZLength.ID_CARD_MRZ_DOCUMENT_NUMBER_LENGTH
                ]
            );
            disclosedData.documentType = string(
                discloseBytes[MRZIndex.ID_CARD_MRZ_DOCUMENT_TYPE_INDEX:MRZIndex.ID_CARD_MRZ_DOCUMENT_TYPE_INDEX
                            + MRZLength.ID_CARD_MRZ_DOCUMENT_TYPE_LENGTH
                ]
            );
        }
    }

    function getDiscloseProofInputs(bytes calldata committedInputs)
        public
        pure
        returns (bytes memory discloseMask, bytes memory discloseBytes)
    {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType proofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (proofType == ProofType.DISCLOSE && length == CommittedInputLen.DISCLOSE_BYTES) {
                discloseMask = committedInputs[offset:offset + MRZLength.MRZ_MAX_LENGTH];
                discloseBytes = committedInputs[offset + MRZLength.MRZ_MAX_LENGTH:offset + MRZLength.MRZ_MAX_LENGTH * 2];
                foundCount++;
            }
            offset += length;
        }
        require(foundCount > 0, "Disclose proof inputs not found");
        require(foundCount == 1, "Found multiple disclose proofs, the proof should only have one");
    }

    function getDateProofInputs(bytes calldata committedInputs, ProofType proofType)
        public
        pure
        returns (uint256 minDate, uint256 maxDate)
    {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (proofType == retrievedProofType && length == CommittedInputLen.COMPARE_EXPIRY) {
                // Get rid of the padding 0s bytes as the timestamp is contained within the first 64 bits
                // i.e. 256 - 64 = 192
                minDate = uint256(bytes32(committedInputs[offset:offset + TIMESTAMP_LENGTH])) >> 192;
                maxDate =
                    uint256(bytes32(committedInputs[offset + TIMESTAMP_LENGTH:offset + TIMESTAMP_LENGTH * 2])) >> 192;
                foundCount++;
            }
            offset += length;
        }
        if (proofType == ProofType.BIRTHDATE) {
            require(foundCount > 0, "Compare birthdate proof inputs not found");
            require(foundCount == 1, "Found multiple compare birthdate proofs, the proof should only have one");
        } else {
            require(foundCount > 0, "Compare expiry date proof inputs not found");
            require(foundCount == 1, "Found multiple compare expiry date proofs, the proof should only have one");
        }
    }

    function getAgeProofInputs(bytes calldata committedInputs) public pure returns (uint8 minAge, uint8 maxAge) {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (retrievedProofType == ProofType.AGE && length == CommittedInputLen.COMPARE_AGE) {
                minAge = uint8(committedInputs[offset]);
                maxAge = uint8(committedInputs[offset + 1]);
                foundCount++;
            }
            offset += length;
        }
        require(foundCount > 0, "Compare age proof inputs not found");
        require(foundCount == 1, "Found multiple compare age proofs, the proof should only have one");
    }

    function getCountryListLength(bytes calldata committedInputs, ProofType proofType)
        public
        pure
        returns (uint256 countryListLength)
    {
        uint256 offset = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (proofType == retrievedProofType && length == CommittedInputLen.INCL_NATIONALITY) {
                for (uint256 j = 0; j < COUNTRY_LIST_LENGTH; j++) {
                    // The circuit constrains that once we've reached the first `0`,
                    // we won't encounter any further nonzero values.
                    // We don't need to include the padding bytes
                    if (committedInputs[offset] == 0) return j;
                    offset += 3;
                }
                offset += length - COUNTRY_LIST_LENGTH * 3;
            } else {
                offset += length;
            }
        }
    }

    function getCountryProofInputs(bytes calldata committedInputs, ProofType proofType)
        public
        pure
        returns (string[] memory countryList, uint256 countryListLength)
    {
        require(
            proofType == ProofType.NATIONALITY_INCLUSION || proofType == ProofType.ISSUING_COUNTRY_INCLUSION
                || proofType == ProofType.NATIONALITY_EXCLUSION || proofType == ProofType.ISSUING_COUNTRY_EXCLUSION,
            "Invalid proof type"
        );
        uint256 offset = 0;
        uint256 foundCount = 0;
        countryListLength = getCountryListLength(committedInputs, proofType);
        countryList = new string[](countryListLength);
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (proofType == retrievedProofType && length == CommittedInputLen.INCL_NATIONALITY) {
                for (uint256 j = 0; j < countryListLength; j++) {
                    countryList[j] = string(committedInputs[offset:offset + 3]);
                    offset += 3;
                }
                offset += length - countryListLength * 3;
                foundCount++;
            } else {
                offset += length;
            }
        }
        if (proofType == ProofType.ISSUING_COUNTRY_INCLUSION) {
            require(foundCount > 0, "Inclusion country proof inputs not found");
            require(foundCount == 1, "Found multiple inclusion country proofs, the proof should only have one");
        } else if (proofType == ProofType.ISSUING_COUNTRY_EXCLUSION) {
            require(foundCount > 0, "Exclusion country proof inputs not found");
            require(foundCount == 1, "Found multiple exclusion country proofs, the proof should only have one");
        } else if (proofType == ProofType.NATIONALITY_INCLUSION) {
            require(foundCount > 0, "Inclusion nationality proof inputs not found");
            require(foundCount == 1, "Found multiple inclusion nationality proofs, the proof should only have one");
        } else if (proofType == ProofType.NATIONALITY_EXCLUSION) {
            require(foundCount > 0, "Exclusion nationality proof inputs not found");
            require(foundCount == 1, "Found multiple exclusion nationality proofs, the proof should only have one");
        }
    }

    function getBindProofInputs(bytes calldata committedInputs) public pure returns (bytes memory data) {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (retrievedProofType == ProofType.BIND && length == CommittedInputLen.BIND) {
                data = committedInputs[offset:offset + BOUND_DATA_LENGTH];
                foundCount++;
            }
            offset += length;
        }
        require(foundCount > 0, "Bind data proof inputs not found");
        require(foundCount == 1, "Found multiple bind data proofs, the proof should only have one");
    }

    function getSanctionsProofInputs(bytes calldata committedInputs)
        public
        pure
        returns (bytes32 sanctionsTreesCommitment, bool isStrict)
    {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (retrievedProofType == ProofType.SANCTIONS && length == CommittedInputLen.SANCTIONS) {
                sanctionsTreesCommitment = bytes32(committedInputs[offset:offset + 32]);
                isStrict = uint8(committedInputs[offset + 32]) == 1;
                foundCount++;
            }
            offset += length;
        }
        require(foundCount > 0, "Sanctions proof inputs not found");
        require(foundCount == 1, "Found multiple sanctions proofs, the proof should only have one");
    }

    function getBoundData(bytes calldata data)
        public
        pure
        returns (address senderAddress, uint256 chainId, string memory customData)
    {
        uint256 offset = 0;
        while (offset < BOUND_DATA_LENGTH) {
            if (data[offset] == bytes1(uint8(BoundDataIdentifier.USER_ADDRESS))) {
                uint16 addressLength = uint16(bytes2(data[offset + 1:offset + 3]));
                senderAddress = address(bytes20(data[offset + 3:offset + 3 + addressLength]));
                offset += 2 + addressLength + 1;
            } else if (data[offset] == bytes1(uint8(BoundDataIdentifier.CHAIN_ID))) {
                uint16 chainIdLength = uint16(bytes2(data[offset + 1:offset + 3]));
                require(chainIdLength <= 32, "Chain id length too long");
                // bytes32 right pads while we want to left pad
                // so we shift the bytes to the right by 256 - (chainIdLength * 8)
                chainId = uint256(bytes32(data[offset + 3:offset + 3 + chainIdLength]) >> (256 - (chainIdLength * 8)));
                offset += 2 + chainIdLength + 1;
            } else if (data[offset] == bytes1(uint8(BoundDataIdentifier.CUSTOM_DATA))) {
                uint16 customDataLength = uint16(bytes2(data[offset + 1:offset + 3]));
                customData = string(data[offset + 3:offset + 3 + customDataLength]);
                offset += 2 + customDataLength + 1;
            } else {
                // Check that the data length is valid
                require(offset > 0 && offset <= BOUND_DATA_LENGTH, "Invalid data length");
                // Check that the padding is valid
                for (uint256 i = offset; i < BOUND_DATA_LENGTH; i++) {
                    require(data[i] == 0, "Invalid padding");
                }
                break;
            }
        }
    }

    function getFacematchProofInputs(bytes calldata committedInputs)
        public
        pure
        returns (
            bytes32 rootKeyHash,
            Environment environment,
            bytes32 appIdHash,
            bytes32 integrityPublicKeyHash,
            FaceMatchMode facematchMode,
            bytes32 revocationRoot
        )
    {
        return readFacematchProofInputs(committedInputs);
    }

    /// @notice Internal, so contracts can call it without linking this library
    function readFacematchProofInputs(bytes calldata committedInputs)
        internal
        pure
        returns (
            bytes32 rootKeyHash,
            Environment environment,
            bytes32 appIdHash,
            bytes32 integrityPublicKeyHash,
            FaceMatchMode facematchMode,
            bytes32 revocationRoot
        )
    {
        uint256 offset = 0;
        uint256 foundCount = 0;
        while (offset < committedInputs.length) {
            ProofType retrievedProofType = ProofType(uint8(committedInputs[offset]));
            uint16 length = uint16(bytes2(committedInputs[offset + 1:offset + 3]));
            offset += 3;
            if (retrievedProofType == ProofType.FACEMATCH && length == CommittedInputLen.FACEMATCH) {
                rootKeyHash = bytes32(committedInputs[offset:offset + 32]);
                environment = Environment(uint8(committedInputs[offset + 32]));
                appIdHash = bytes32(committedInputs[offset + 33:offset + 65]);
                integrityPublicKeyHash = bytes32(committedInputs[offset + 65:offset + 97]);
                facematchMode = FaceMatchMode(uint8(committedInputs[offset + 97]));
                revocationRoot = bytes32(committedInputs[offset + 98:offset + 130]);
                foundCount++;
            }
            offset += length;
        }
        require(foundCount > 0, "Facematch proof inputs not found");
        require(foundCount == 1, "Found multiple facematch proofs, the proof should only have one");
    }

    /**
     * @notice Reads the parameters of the attested ID proof, which must be the first committed input entry
     */
    function getAttestedIdProofInputs(bytes calldata committedInputs)
        internal
        pure
        returns (
            bytes32 rootKeyHash,
            Environment environment,
            bytes32 appIdHash,
            bytes32 integrityPublicKeyHash,
            FaceMatchMode facematchMode,
            bytes32 revocationRoot
        )
    {
        require(
            committedInputs.length >= 3 && uint8(committedInputs[0]) == uint8(ProofType.ATTESTED_ID),
            "Attested ID proof inputs not found"
        );
        require(
            uint16(bytes2(committedInputs[1:3])) == CommittedInputLen.ATTESTED_ID
                && committedInputs.length >= 3 + CommittedInputLen.ATTESTED_ID,
            "Invalid attested ID proof inputs length"
        );
        rootKeyHash = bytes32(committedInputs[3:35]);
        environment = Environment(uint8(committedInputs[35]));
        appIdHash = bytes32(committedInputs[36:68]);
        integrityPublicKeyHash = bytes32(committedInputs[68:100]);
        facematchMode = FaceMatchMode(uint8(committedInputs[100]));
        revocationRoot = bytes32(committedInputs[101:133]);
    }

    /**
     * @notice Whether any committed input entry is of the given proof type
     */
    function containsProofType(bytes calldata committedInputs, ProofType proofType) internal pure returns (bool) {
        uint256 offset = 0;
        while (offset < committedInputs.length) {
            if (uint8(committedInputs[offset]) == uint8(proofType)) {
                return true;
            }
            offset += 3 + uint16(bytes2(committedInputs[offset + 1:offset + 3]));
        }
        return false;
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/StringUtils.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

library StringUtils {
    function equals(string memory a, string memory b) internal pure returns (bool) {
        return keccak256(bytes(a)) == keccak256(bytes(b));
    }

    function isEmpty(string memory a) internal pure returns (bool) {
        return bytes(a).length == 0;
    }
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/Types.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

struct ProofVerifier {
    bytes32 vkeyHash;
    address verifier;
}

enum ProofType {
    DISCLOSE,
    AGE,
    BIRTHDATE,
    EXPIRY_DATE,
    NATIONALITY_INCLUSION,
    NATIONALITY_EXCLUSION,
    ISSUING_COUNTRY_INCLUSION,
    ISSUING_COUNTRY_EXCLUSION,
    BIND,
    SANCTIONS,
    FACEMATCH,
    ATTESTED_ID
}

enum BoundDataIdentifier {
    NONE,
    USER_ADDRESS,
    CHAIN_ID,
    CUSTOM_DATA
}

enum FaceMatchMode {
    NONE,
    REGULAR,
    STRICT
}

enum Environment {
    DEVELOPMENT,
    PRODUCTION
}

enum NullifierType {
    NON_SALTED_NULLIFIER,
    SALTED_NULLIFIER,
    NON_SALTED_MOCK_NULLIFIER,
    SALTED_MOCK_NULLIFIER,
    NONE_NULLIFIER
}

enum OS {
    ANY,
    IOS,
    ANDROID
}

// ProofVerificationParams
// │
// ├── bytes32 version                        // Version identifier of the verifier
// │
// ├── ProofVerificationData proofVerificationData
// │   ├── bytes32 vkeyHash                   // Verification key hash
// │   ├── bytes proof                        // The actual ZK proof
// │   └── bytes32[] publicInputs             // Array of public inputs (7+ elements)
// │       │                                  // Use PublicInputsCast.asStruct() for structured access:
// │       ├── [0] certificate_registry_root  // Field - struct.certificateRegistryRoot
// │       ├── [1] circuit_registry_root      // Field - struct.circuitRegistryRoot
// │       ├── [2] current_date               // u64 - PublicInputsCast.getCurrentDate(struct)
// │       ├── [3] service_scope              // Field - struct.serviceScope
// │       ├── [4] service_subscope           // Field - struct.serviceSubscope
// │       ├── [5:5+N] param_commitments      // Field[N] - PublicInputsCast.getParamCommitment(array, index)
// │       ├── [5+N] nullifier_type           // u8 - PublicInputsCast.getNullifierType(array, paramCount)
// │       ├── [6+N] scoped_nullifier         // Field - PublicInputsCast.getScopedNullifier(array, paramCount)
// │       ├── [7+N] oprf_pk_hash             // Poseidon2(pk.x, pk.y) for SALTED, 0 for NON_SALTED
// │       └── [8+N] verification_method        // What verified the ID, see lib/VerificationMethods.sol
// │
// ├── bytes committedInputs              // Preimages of param_commitments
// │
// └── ServiceConfig serviceConfig
//     ├── uint256 validityPeriodInSeconds    // How long the proof is valid
//     ├── string domain                      // Service domain
//     ├── string scope                       // Service scope
//     └── bool devMode                       // Development mode flag
struct ProofVerificationParams {
    bytes32 version;
    ProofVerificationData proofVerificationData;
    bytes committedInputs;
    ServiceConfig serviceConfig;
}

struct ProofVerificationData {
    bytes32 vkeyHash;
    bytes proof;
    bytes32[] publicInputs;
}

struct ServiceConfig {
    uint256 validityPeriodInSeconds;
    string domain;
    string scope;
    bool devMode;
}

struct DisclosedData {
    string name;
    string issuingCountry;
    string nationality;
    string gender;
    string birthDate;
    string expiryDate;
    string documentNumber;
    string documentType;
}

struct BoundData {
    address senderAddress;
    uint256 chainId;
    string customData;
}

lib/zkpassport-packages/packages/registry-contracts/src/lib/VerificationMethods.sol

// SPDX-License-Identifier: Apache-2.0
// Copyright © 2026 ZKPassport
/*
 ______ _     _  _____  _______ _______ _______  _____   _____   ______ _______
  ____/ |____/  |_____] |_____| |______ |______ |_____] |     | |_____/    |
 /_____ |    \_ |       |     | ______| ______| |       |_____| |    \_    |

*/

pragma solidity ^0.8.30;

// The assurance tier of a credential: tier 1 is schemes 100-199, tier 2 is 200-299
library VerificationTier {
    // The issuer signed the data
    uint256 constant GOVERNMENT_SIGNED = 1;
    // A device attested a camera read of the data, with a strict face match
    uint256 constant DEVICE_ATTESTED = 2;
}

// How the ID's data was verified: the last public input of the outer proof
library VerificationMethod {
    // The eMRTD chip, signed by the issuing country (CSCA -> DSC)
    uint256 constant ICAO_CHIP = 100;
    uint256 constant UIDAI_AADHAAR = 101;
    uint256 constant JPKI = 102;
    uint256 constant ISO_MDOC = 103;
    // The data page read by camera on iOS, attested by App Attest
    uint256 constant ATTESTED_CAPTURE_IOS = 200;
    // The data page read by camera on Android, attested by Play Integrity
    uint256 constant ATTESTED_CAPTURE_ANDROID = 201;
}

library VerificationMethods {
    /// @notice The tier of a scheme, by explicit range; 0 for a value in no tier's range
    function tierOf(uint256 scheme) internal pure returns (uint256) {
        if (scheme >= 100 && scheme < 200) return VerificationTier.GOVERNMENT_SIGNED;
        if (scheme >= 200 && scheme < 300) return VerificationTier.DEVICE_ATTESTED;
        return 0;
    }

    /// @notice Whether a policy entry names a whole tier rather than one exact scheme
    function isTier(uint256 entry) internal pure returns (bool) {
        return entry == VerificationTier.GOVERNMENT_SIGNED || entry == VerificationTier.DEVICE_ATTESTED;
    }

    /**
     * @notice Whether `verify()` can accept a scheme at all: an issuer-signed one, or a device-attested
     *         one whose attestation it then checks. Which of those a service accepts is the service's
     *         choice, made with the helper's enforceVerificationMethod.
     */
    function isVerifiable(uint256 scheme) internal pure returns (bool) {
        // Only the schemes a circuit proves today, each by name: a new scheme must be added here
        // with its own checks, never accepted for falling in a tier's range
        return scheme == VerificationMethod.ICAO_CHIP || scheme == VerificationMethod.UIDAI_AADHAAR
            || scheme == VerificationMethod.ATTESTED_CAPTURE_IOS
            || scheme == VerificationMethod.ATTESTED_CAPTURE_ANDROID;
    }

    /**
     * @notice Whether a list of accepted verification methods includes a scheme. An entry that is a
     *         tier (1 or 2) stands for every scheme of that tier; any other entry is one exact scheme. An
     *         empty list accepts tier 1 only.
     */
    function isAllowed(uint256 scheme, uint256[] memory allowedVerificationMethods) internal pure returns (bool) {
        uint256 tier = tierOf(scheme);
        if (allowedVerificationMethods.length == 0) {
            return tier == VerificationTier.GOVERNMENT_SIGNED;
        }
        for (uint256 i = 0; i < allowedVerificationMethods.length; i++) {
            uint256 entry = allowedVerificationMethods[i];
            if (entry == scheme || (isTier(entry) && entry == tier)) {
                return true;
            }
        }
        return false;
    }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {
    "lib/zkpassport-packages/packages/registry-contracts/src/VerifierHelper.sol": {
      "InputsExtractor": "0x9bba5c7e08acde6b3f8f6a9c26bb7a3f1a254f4e"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "@zkpassport/registry-contracts/=lib/zkpassport-packages/packages/registry-contracts/src/",
    "forge-std/=lib/forge-std/src/",
    "zkpassport-packages/=lib/zkpassport-packages/packages/registry-contracts/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.