@@ -2,6 +2,15 @@ import { discloseIndices, revealedDataIndices } from './constants.js';
22import { AttestationId , GenericDiscloseOutput } from 'src/types/types.js' ;
33import { getRevealedDataBytes } from './proof.js' ;
44
5+ /**
6+ * Removes null bytes (\x00) from a string
7+ * @param str - The string to clean
8+ * @returns The string with null bytes removed
9+ */
10+ export const removeNullBytes = ( str : string ) : string => {
11+ return str . replace ( / \x00 / g, '' ) ;
12+ } ;
13+
514export const formatRevealedDataPacked = (
615 attestationId : AttestationId ,
716 publicSignals : string [ ]
@@ -12,7 +21,7 @@ export const formatRevealedDataPacked = (
1221 const nullifier = publicSignals [ discloseIndices [ attestationId ] . nullifierIndex ] ;
1322 const forbiddenCountriesListPacked = publicSignals . slice (
1423 discloseIndices [ attestationId ] . forbiddenCountriesListPackedIndex ,
15- discloseIndices [ attestationId ] . forbiddenCountriesListPackedIndex + 3
24+ discloseIndices [ attestationId ] . forbiddenCountriesListPackedIndex + 4
1625 ) ;
1726 const issuingState = revealedDataPackedString
1827 . subarray (
@@ -35,48 +44,89 @@ export const formatRevealedDataPacked = (
3544 revealedDataIndices [ attestationId ] . idNumberEnd + 1
3645 )
3746 . toString ( 'utf-8' ) ;
38- const nationality = revealedDataPackedString
39- . subarray (
40- revealedDataIndices [ attestationId ] . nationalityStart ,
41- revealedDataIndices [ attestationId ] . nationalityEnd + 1
42- )
43- . toString ( 'utf-8' ) ;
44- const dateOfBirth = revealedDataPackedString
45- . subarray (
46- revealedDataIndices [ attestationId ] . dateOfBirthStart ,
47- revealedDataIndices [ attestationId ] . dateOfBirthEnd + 1
47+
48+ let nationality : string ;
49+ if ( attestationId === 3 ) {
50+ nationality = 'IND' ;
51+ } else {
52+ nationality = revealedDataPackedString
53+ . subarray (
54+ revealedDataIndices [ attestationId ] . nationalityStart ,
55+ revealedDataIndices [ attestationId ] . nationalityEnd + 1
56+ )
57+ . toString ( 'utf-8' ) ;
58+ }
59+ let dateOfBirth : string ;
60+ if ( attestationId === 3 ) {
61+ dateOfBirth = new Array (
62+ revealedDataPackedString . subarray (
63+ revealedDataIndices [ attestationId ] . dateOfBirthStart ,
64+ revealedDataIndices [ attestationId ] . dateOfBirthEnd + 1
65+ )
4866 )
49- . toString ( 'utf-8' ) ;
67+ . map ( Number )
68+ . map ( String )
69+ . join ( '' ) ;
70+ } else {
71+ dateOfBirth = revealedDataPackedString
72+ . subarray (
73+ revealedDataIndices [ attestationId ] . dateOfBirthStart ,
74+ revealedDataIndices [ attestationId ] . dateOfBirthEnd + 1
75+ )
76+ . toString ( 'utf-8' ) ;
77+ }
5078 const gender = revealedDataPackedString
5179 . subarray (
5280 revealedDataIndices [ attestationId ] . genderStart ,
5381 revealedDataIndices [ attestationId ] . genderEnd + 1
5482 )
5583 . toString ( 'utf-8' ) ;
56- const expiryDate = revealedDataPackedString
57- . subarray (
58- revealedDataIndices [ attestationId ] . expiryDateStart ,
59- revealedDataIndices [ attestationId ] . expiryDateEnd + 1
60- )
61- . toString ( 'utf-8' ) ;
62- const olderThan = Buffer . from (
63- revealedDataPackedString . subarray (
64- revealedDataIndices [ attestationId ] . olderThanStart ,
65- revealedDataIndices [ attestationId ] . olderThanEnd + 1
66- )
67- ) . toString ( 'utf-8' ) ;
84+ let expiryDate : string ;
85+ if ( attestationId === 3 ) {
86+ expiryDate = 'UNAVAILABLE' ;
87+ } else {
88+ expiryDate = revealedDataPackedString
89+ . subarray (
90+ revealedDataIndices [ attestationId ] . expiryDateStart ,
91+ revealedDataIndices [ attestationId ] . expiryDateEnd + 1
92+ )
93+ . toString ( 'utf-8' ) ;
94+ }
95+ let olderThan : string ;
96+ if ( attestationId === 3 ) {
97+ olderThan = revealedDataPackedString
98+ . subarray (
99+ revealedDataIndices [ attestationId ] . olderThanStart ,
100+ revealedDataIndices [ attestationId ] . olderThanEnd + 1
101+ )
102+ . toString ( 'utf-8' ) ;
103+ } else {
104+ olderThan = revealedDataPackedString
105+ . subarray (
106+ revealedDataIndices [ attestationId ] . olderThanStart ,
107+ revealedDataIndices [ attestationId ] . olderThanEnd + 1
108+ ) [ 0 ]
109+ . toString ( )
110+ . padStart ( 2 , '0' ) ;
111+ }
68112 const ofac = Array . from (
69113 revealedDataPackedString . subarray (
70114 revealedDataIndices [ attestationId ] . ofacStart ,
71115 revealedDataIndices [ attestationId ] . ofacEnd + 1
72116 )
73- ) . map ( Boolean ) ;
117+ )
118+ . map ( Boolean )
119+ . map ( ( x ) => ! x ) ;
120+
121+ if ( ofac . length < 3 ) {
122+ ofac . unshift ( false ) ;
123+ }
74124
75125 return {
76126 nullifier : nullifier . toString ( ) ,
77127 forbiddenCountriesListPacked : forbiddenCountriesListPacked ,
78- issuingState : issuingState ,
79- name : name ,
128+ issuingState : removeNullBytes ( issuingState ) ,
129+ name : removeNullBytes ( name ) ,
80130 idNumber : idNumber ,
81131 nationality : nationality ,
82132 dateOfBirth : dateOfBirth ,
0 commit comments