-
Notifications
You must be signed in to change notification settings - Fork 180
Feat/aadhaar sdk #1082
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/aadhaar sdk #1082
Changes from all commits
430a6fd
08ccf79
6e7c29a
b1dc0ba
761fb2f
b335e66
e1a5825
846956d
712e780
74605c0
f7e9c40
9ff1ae9
049874b
08264e5
dd681ac
b2c89e0
77626c4
9ccce41
4e97eec
a2c6969
55a0edc
57a40a8
43a0b81
9a67634
09f1b90
0428ac4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,15 @@ import { discloseIndices, revealedDataIndices } from './constants.js'; | |||||||||||||||||||||||||||||||||||||||||||
| import { AttestationId, GenericDiscloseOutput } from 'src/types/types.js'; | ||||||||||||||||||||||||||||||||||||||||||||
| import { getRevealedDataBytes } from './proof.js'; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||
| * Removes null bytes (\x00) from a string | ||||||||||||||||||||||||||||||||||||||||||||
| * @param str - The string to clean | ||||||||||||||||||||||||||||||||||||||||||||
| * @returns The string with null bytes removed | ||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||
| export const removeNullBytes = (str: string): string => { | ||||||||||||||||||||||||||||||||||||||||||||
| return str.replace(/\x00/g, ''); | ||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| export const formatRevealedDataPacked = ( | ||||||||||||||||||||||||||||||||||||||||||||
| attestationId: AttestationId, | ||||||||||||||||||||||||||||||||||||||||||||
| publicSignals: string[] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -12,7 +21,7 @@ export const formatRevealedDataPacked = ( | |||||||||||||||||||||||||||||||||||||||||||
| const nullifier = publicSignals[discloseIndices[attestationId].nullifierIndex]; | ||||||||||||||||||||||||||||||||||||||||||||
| const forbiddenCountriesListPacked = publicSignals.slice( | ||||||||||||||||||||||||||||||||||||||||||||
| discloseIndices[attestationId].forbiddenCountriesListPackedIndex, | ||||||||||||||||||||||||||||||||||||||||||||
| discloseIndices[attestationId].forbiddenCountriesListPackedIndex + 3 | ||||||||||||||||||||||||||||||||||||||||||||
| discloseIndices[attestationId].forbiddenCountriesListPackedIndex + 4 | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
| const issuingState = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,48 +44,89 @@ export const formatRevealedDataPacked = ( | |||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].idNumberEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| const nationality = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].nationalityStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].nationalityEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| const dateOfBirth = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| let nationality: string; | ||||||||||||||||||||||||||||||||||||||||||||
| if (attestationId === 3) { | ||||||||||||||||||||||||||||||||||||||||||||
| nationality = 'IND'; | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| nationality = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].nationalityStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].nationalityEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| let dateOfBirth: string; | ||||||||||||||||||||||||||||||||||||||||||||
| if (attestationId === 3) { | ||||||||||||||||||||||||||||||||||||||||||||
| dateOfBirth = new Array( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataPackedString.subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| .map(Number) | ||||||||||||||||||||||||||||||||||||||||||||
| .map(String) | ||||||||||||||||||||||||||||||||||||||||||||
| .join(''); | ||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Aadhaar Date Parsing Array ErrorThe |
||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ Verification inconclusiveAadhaar DOB parsing is broken (new Array(...) over a TypedArray). new Array(typedArray) creates a 1‑element array, yielding "NaN" DOB. Use Array.from over the subarray. Apply: - dateOfBirth = new Array(
- revealedDataPackedString.subarray(
- revealedDataIndices[attestationId].dateOfBirthStart,
- revealedDataIndices[attestationId].dateOfBirthEnd + 1
- )
- )
- .map(Number)
- .map(String)
- .join('');
+ {
+ const dobBytes = revealedDataPackedString.subarray(
+ revealedDataIndices[attestationId].dateOfBirthStart,
+ revealedDataIndices[attestationId].dateOfBirthEnd + 1
+ );
+ dateOfBirth = Array.from(dobBytes, (b) => String(b)).join('');
+ }If bytes are ASCII digits, switch mapper to String.fromCharCode(b). Please confirm which encoding the circuit emits for Aadhaar DOB. Critical: Fix Aadhaar DOB parsing — convert TypedArray with Array.from File: sdk/core/src/utils/id.ts Lines: 60-70 new Array(typedArray) creates a 1-element array (producing "NaN" DOB). Convert the subarray to a real array/string with Array.from or spread. Apply the diff below. - dateOfBirth = new Array(
- revealedDataPackedString.subarray(
- revealedDataIndices[attestationId].dateOfBirthStart,
- revealedDataIndices[attestationId].dateOfBirthEnd + 1
- )
- )
- .map(Number)
- .map(String)
- .join('');
+ {
+ const dobBytes = revealedDataPackedString.subarray(
+ revealedDataIndices[attestationId].dateOfBirthStart,
+ revealedDataIndices[attestationId].dateOfBirthEnd + 1
+ );
+ dateOfBirth = Array.from(dobBytes, (b) => String(b)).join('');
+ }If bytes are ASCII digits, use String.fromCharCode(b) in the mapper. Confirm which encoding the circuit emits for Aadhaar DOB. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| dateOfBirth = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].dateOfBirthEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| const gender = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].genderStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].genderEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| const expiryDate = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].expiryDateStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].expiryDateEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| const olderThan = Buffer.from( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataPackedString.subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ).toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| let expiryDate: string; | ||||||||||||||||||||||||||||||||||||||||||||
| if (attestationId === 3) { | ||||||||||||||||||||||||||||||||||||||||||||
| expiryDate = 'UNAVAILABLE'; | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| expiryDate = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].expiryDateStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].expiryDateEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| let olderThan: string; | ||||||||||||||||||||||||||||||||||||||||||||
| if (attestationId === 3) { | ||||||||||||||||||||||||||||||||||||||||||||
| olderThan = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .toString('utf-8'); | ||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||
| olderThan = revealedDataPackedString | ||||||||||||||||||||||||||||||||||||||||||||
| .subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].olderThanEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| )[0] | ||||||||||||||||||||||||||||||||||||||||||||
| .toString() | ||||||||||||||||||||||||||||||||||||||||||||
| .padStart(2, '0'); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
| const ofac = Array.from( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataPackedString.subarray( | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].ofacStart, | ||||||||||||||||||||||||||||||||||||||||||||
| revealedDataIndices[attestationId].ofacEnd + 1 | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| ).map(Boolean); | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| .map(Boolean) | ||||||||||||||||||||||||||||||||||||||||||||
| .map((x) => !x); | ||||||||||||||||||||||||||||||||||||||||||||
Nesopie marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if (ofac.length < 3) { | ||||||||||||||||||||||||||||||||||||||||||||
| ofac.unshift(false); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||
| nullifier: nullifier.toString(), | ||||||||||||||||||||||||||||||||||||||||||||
| forbiddenCountriesListPacked: forbiddenCountriesListPacked, | ||||||||||||||||||||||||||||||||||||||||||||
| issuingState: issuingState, | ||||||||||||||||||||||||||||||||||||||||||||
| name: name, | ||||||||||||||||||||||||||||||||||||||||||||
| issuingState: removeNullBytes(issuingState), | ||||||||||||||||||||||||||||||||||||||||||||
| name: removeNullBytes(name), | ||||||||||||||||||||||||||||||||||||||||||||
| idNumber: idNumber, | ||||||||||||||||||||||||||||||||||||||||||||
| nationality: nationality, | ||||||||||||||||||||||||||||||||||||||||||||
| dateOfBirth: dateOfBirth, | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.