Utilize Passport Attributes
In the happy-birthday example, we demonstrated one way to utilize the passport information when integrating Self. Note that the passport details—and the forbiddenCountries data—are bundled into the circuit’s public signals in order to reduce onchain data. This bundled format is not very user-friendly for reading.
If you simply need the data in a readable format, you can call the following functions from the IdentityVerificationHub.
Readable Data Extraction
Get Readable Passport Data
You can retrieve readable attributes by calling:
Get Readable Forbidden Countries
Similarly, to extract the forbiddenCountries list in a readable format:
In the getReadableRevealedData
function, you specify the types of data you want to expose to reduce unnecessary processing and save gas. Please use the following enum defined in the IIdentityVerificationHub:
Additional Libraries for Enhanced Flexibility
Self provides several convenient functions as libraries so that external contracts can easily use our features. The two main libraries included in @selfxyz/contracts
are Formatter and CircuitAttributeHandler. Below is a summary of their key functions:
Formatter
formatName Converts raw name data from the passport into a human-readable format.
formatDate Transforms date data from the YYMMDD format into the DD-MM-YY format.
numAsciiToUint Converts numerical data represented as ASCII characters into a uint.
fieldElementToBytes Converts the three bn254 field elements of
revealedDataPacked
into a single bytes array.extractForbiddenCountriesFromPacked Transforms the four bn254 field elements of
forbiddenCountriesListPacked
into a readable array of three-letter country codes.proofDateToUnixTimestamp Converts the six proof-generated date signals into the Unix timestamp for midnight of that day.
dateToUnixTimestamp Converts a date string in YYMMDD format into the Unix timestamp for midnight of that day.
substring Used to extract a substring from a given string.
parseDatePart Converts a date component represented as a string into a numeric value.
toTimestamp Accepts numeric year, month, and day values and returns the Unix timestamp for midnight of that day.
isLeapYear Checks whether a given year is a leap year when converting to a timestamp.
CircuitAttributeHandler
getIssuingState Extracts the issuing state information from the bytes array produced by
fieldElementToBytes
.getName Extracts the name from the bytes data.
getPassportNumber Extracts the passport number from the bytes data.
getNationality Extracts the nationality from the bytes data.
getDateOfBirth Extracts the date of birth from the bytes data.
getGender Extracts the gender from the bytes data.
getExpiryDate Extracts the expiry date from the bytes data.
getOlderThan Extracts the age verification ("older than") value from the bytes data.
getPassportNoOfac Extracts the OFAC check result for the passport number from the bytes data.
getNameAndDobOfac Extracts the OFAC check result for the name and date of birth from the bytes data.
getNameAndYobOfac Extracts the OFAC check result for the name and year of birth from the bytes data.
compareOfac Verifies that the OFAC check passes without issues.
compareOlderThan Checks that the proof meets the required minimum age.
extractStringAttributes Extracts string attributes from specific positions within the bytes data.
Use these functions in your contracts as needed to enhance the usability of the passport data and to interact flexibly with Self’s verification functionality.
Last updated