Skip to content

Queries

The ZK Query Language provides a simple and flexible way for developers to design customised authentication requirements based on users' credentials. It utilises the Atomic Query MTP V2 Circuit for zero-knowledge verification.

The query language helps in building a query by the Verifier and presents it to the wallet holder via QR code. Once the user generates a proof in response to the query, the Verifier can easily check if the query is satisfied or not.

The six operators available provide versatility in crafting queries:

Operator 1: Equals

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/0xPolygonID/tutorial-examples/main/credential-schema/schemas-examples/proof-of-humanity/proof-of-humanity.jsonld",
            "credentialSubject": {
                "isHuman": {
                   "$eq": 1
                    }
                },
            "type": "ProofOfHumanity"
        }
    }

Credential Type: ProofOfHumanity

Checks if a user has been verified as a human or bot.

Operator 2: Less Than

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v4.jsonld",
            "credentialSubject": {
                "birthday": {
                   "$lt": 20010101
                    }
                },
            "type": "KYCAgeCredential"
        }
    }

Credential Type: KYCAgeCredential

Checks if a user has been born before 2001/01/01.

Operator 3: Greater Than

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/0xPolygonID/tutorial-examples/main/credential-schema/schemas-examples/employee-data/employee-data.jsonld",
            "credentialSubject": {
                "monthlySalary": {
                    "$gt": 1000
                    }
                },
            "type": "EmployeeData"
        }
    }

Credential Type: EmployeeData

Checks if the salary is greater than 1000.

Operator 4: In

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/0xPolygonID/tutorial-examples/main/credential-schema/schemas-examples/proof-of-dao-role/proof-of-dao-role.jsonld",
            "credentialSubject": {
                "role": {
                    "$in": [4,5]
                    }
                },
            "type": "ProofOfDaoRole"
        }
    }

Credential Type: ProofOfDaoRole

Checks if the user belongs to either role type 4 or 5.

Operator 5: Not In

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v4.jsonld",
            "credentialSubject": {
                "countryCode": {
                    "$nin": [840, 120, 340, 509]
                    }
                },
            "type": "KYCCountryOfResidenceCredential"
        }
    }

Credential Type: KYCCountryOfResidenceCredential

Checks if the user does not belong to any of the following codes: 840, 120, 340, 509.

Operator 6: Not Equal

    {
        "id": 1,
        "circuitId": "credentialAtomicQuerySigV2OnChain",
        "query": {
            "allowedIssuers": [ "*"],
            "context": "https://raw.githubusercontent.com/iden3/claim-schema-vocab/main/schemas/json-ld/kyc-v4.jsonld",
            "credentialSubject": {
                "countryCode": {
                     "$ne": 840
                    }
                },
            "type": "KYCCountryOfResidenceCredential"
        }
    }

Credential Type: KYCCountryOfResidenceCredential

Checks if the user does not belong to the country codes: 840.