Skip to main content

Age Verification

You can verify someone's age without learning their date of birth nor their actual age.

These examples use the @zkpassport/ui card. The query you build is what matters — see Basic Usage for how to use the SDK directly instead.

Verify if the user is over 18 years old

You will not learn their date of birth nor their actual age, only that they are 18+.

import { ZKPassportQRCode } from "@zkpassport/ui/react";

<ZKPassportQRCode
name="ZKPassport"
logo="https://zkpassport.id/logo.png"
purpose="Prove you are 18+ years old"
scope="adult"
query={(queryBuilder) => queryBuilder.gte("age", 18).done()}
onResult={({ verified, result }) => {
if (verified) {
const isOver18 = result.age.gte.result;
console.log("User is 18+ years old", isOver18);
} else {
console.log("Verification failed");
}
}}
/>;

Verify if the user is between 18 and 25 years old

Use two bounds, or the range operator (both bounds inclusive). Only the query and result handling change — drop them into the same card as above.

// gte is greater than or equal to, lte is less than or equal to
const query = (queryBuilder) => queryBuilder.gte("age", 18).lte("age", 25).done();
// Alternatively, use the range operator (both bounds inclusive)
// const query = (queryBuilder) => queryBuilder.range("age", 18, 25).done();

const onResult = ({ verified, result }) => {
if (verified) {
const isBetween18And25 = result.age.gte.result && result.age.lte.result;
// const isBetween18And25 = result.age.range.result;
console.log("User is between 18 and 25 years old", isBetween18And25);
} else {
console.log("Verification failed");
}
};