Skip to content

Commit 729ee76

Browse files
NesopieVishalkulkarni45shazarreaaronmgdrtransphorm
authored
Feat/aadhaar sdk (#1082)
* feat: add aadhaar support to the ts sdk * feat: aadhaar support to go sdk * chore: refactor * move clearPassportData, markCurrentDocumentAsRegistered, reStorePassportDataWithRightCSCA to SDK (#1041) * Move self app store to mobile sdk (#1040) * chore(mobile-sdk-alpha): remove unused tslib dependency (#1053) * remove tslib -- seems unused * remove deps accidentally added to root * build file * remove unused imports (#1055) * fix: sha256 signed attr tests (#1058) * fix mock screen launch (#1059) * Hotfix: Belgium ID cards (#1061) * feat: parse belgium TD1 mrz android * feat: Parse Belgium TD1 MRZ IOS * fix: OFAC trees not found (#1060) * fix: relax OFAC tree response validation * test: cover OFAC tree edge cases * fix stateless * revert and fix types * fix tests * [SELF-723] feat: add structured NFC and Proof logging (#1048) * feat: add structured NFC logging * fix ci * Fix: add deps * logging fixes. use breadcrumbs * fix android build * update SeverityLevel * [SELF-705] feat: add proof event logging (#1057) * feat: add proof event logging * refactor: unify sentry event logging * fix types * fix mock * simplify * code rabbit feedback * fix tests --------- Co-authored-by: seshanthS <[email protected]> * skip on dev (#1063) * don't get fancy just disable (#1064) * saw it building so gonna try (#1065) * chore: bump v2.6.5 rd2 (#1067) * commit wip version bump * remove from building * chore: update tooling dependencies (#1069) * chore: update tooling dependencies * chore: align react typings and node types * update lock * chore: minor fixes across monorepo (#1068) * small fixes * fixes * fix gesture handler error * ci fixes * fix yarn build; add workflow ci (#1075) * add new workspace ci * disable package version check for now * build before checks * format * fix in future pr * feat: add functions for disclosing aadhaar attributes (#1033) * feat: add functions for disclosing aadhaar attributes * format * chore: update monorepo artifacts (#1079) * remove unneeded artifacts, skip building circuits * update md files * chore: update hub contract address * format * fix: add aadhaar in AllIds * chore: bump to v1.1.0-beta --------- Co-authored-by: vishal <[email protected]> Co-authored-by: Leszek Stachowski <[email protected]> Co-authored-by: Aaron DeRuvo <[email protected]> Co-authored-by: Justin Hernandez <[email protected]> Co-authored-by: Seshanth.S🐺 <[email protected]> Co-authored-by: seshanthS <[email protected]>
1 parent f85a23a commit 729ee76

File tree

8 files changed

+293
-70
lines changed

8 files changed

+293
-70
lines changed

sdk/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@selfxyz/core",
3-
"version": "1.0.8",
3+
"version": "1.1.0-beta.0",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/selfxyz/self"

sdk/core/src/SelfBackendVerifier.ts

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const CELO_MAINNET_RPC_URL = 'https://forno.celo.org';
2727
const CELO_TESTNET_RPC_URL = 'https://alfajores-forno.celo-testnet.org';
2828

2929
const IDENTITY_VERIFICATION_HUB_ADDRESS = '0xe57F4773bd9c9d8b6Cd70431117d353298B9f5BF';
30-
const IDENTITY_VERIFICATION_HUB_ADDRESS_STAGING = '0x68c931C9a534D37aa78094877F46fE46a49F1A51';
30+
const IDENTITY_VERIFICATION_HUB_ADDRESS_STAGING = '0x16ECBA51e18a4a7e61fdC417f0d47AFEeDfbed74';
3131

3232
export class SelfBackendVerifier {
3333
protected scope: string;
@@ -217,20 +217,40 @@ export class SelfBackendVerifier {
217217
});
218218
}
219219

220-
const circuitTimestampYy = [
221-
2,
222-
0,
223-
publicSignals[discloseIndices[attestationId].currentDateIndex],
224-
publicSignals[discloseIndices[attestationId].currentDateIndex + 1],
225-
];
226-
const circuitTimestampMm = [
227-
publicSignals[discloseIndices[attestationId].currentDateIndex + 2],
228-
publicSignals[discloseIndices[attestationId].currentDateIndex + 3],
229-
];
230-
const circuitTimestampDd = [
231-
publicSignals[discloseIndices[attestationId].currentDateIndex + 4],
232-
publicSignals[discloseIndices[attestationId].currentDateIndex + 5],
233-
];
220+
let circuitTimestampYy: number[];
221+
let circuitTimestampMm: number[];
222+
let circuitTimestampDd: number[];
223+
if (attestationId === 3) {
224+
circuitTimestampYy = String(publicSignals[discloseIndices[attestationId].currentDateIndex])
225+
.split('')
226+
.map(Number);
227+
circuitTimestampMm = String(
228+
publicSignals[discloseIndices[attestationId].currentDateIndex + 1]
229+
)
230+
.split('')
231+
.map(Number);
232+
circuitTimestampDd = String(
233+
publicSignals[discloseIndices[attestationId].currentDateIndex + 2]
234+
)
235+
.split('')
236+
.map(Number);
237+
} else {
238+
circuitTimestampYy = [
239+
2,
240+
0,
241+
+publicSignals[discloseIndices[attestationId].currentDateIndex],
242+
+publicSignals[discloseIndices[attestationId].currentDateIndex + 1],
243+
];
244+
circuitTimestampMm = [
245+
+publicSignals[discloseIndices[attestationId].currentDateIndex + 2],
246+
+publicSignals[discloseIndices[attestationId].currentDateIndex + 3],
247+
];
248+
circuitTimestampDd = [
249+
+publicSignals[discloseIndices[attestationId].currentDateIndex + 4],
250+
+publicSignals[discloseIndices[attestationId].currentDateIndex + 5],
251+
];
252+
}
253+
234254
const circuitTimestamp = new Date(
235255
Number(circuitTimestampYy.join('')),
236256
Number(circuitTimestampMm.join('')) - 1,

sdk/core/src/utils/constants.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ export const discloseIndices = {
2727
userIdentifierIndex: 20,
2828
passportNoSmtRootIndex: 99,
2929
},
30+
3: {
31+
revealedDataPackedIndex: 2,
32+
forbiddenCountriesListPackedIndex: 6,
33+
nullifierIndex: 0,
34+
attestationIdIndex: 10,
35+
merkleRootIndex: 16,
36+
currentDateIndex: 11,
37+
namedobSmtRootIndex: 14,
38+
nameyobSmtRootIndex: 15,
39+
scopeIndex: 17,
40+
userIdentifierIndex: 18,
41+
passportNoSmtRootIndex: 99,
42+
},
3043
} as const;
3144

3245
type RevealedDataFields =
@@ -84,6 +97,26 @@ export const revealedDataIndices: Record<
8497
ofacStart: 92,
8598
ofacEnd: 93,
8699
},
100+
3: {
101+
issuingStateStart: 81,
102+
issuingStateEnd: 111,
103+
nameStart: 9,
104+
nameEnd: 70,
105+
idNumberStart: 71,
106+
idNumberEnd: 74,
107+
nationalityStart: 999,
108+
nationalityEnd: 999,
109+
dateOfBirthStart: 1,
110+
dateOfBirthEnd: 8,
111+
genderStart: 0,
112+
genderEnd: 0,
113+
expiryDateStart: 999,
114+
expiryDateEnd: 999,
115+
olderThanStart: 118,
116+
olderThanEnd: 118,
117+
ofacStart: 116,
118+
ofacEnd: 117,
119+
},
87120
} as const;
88121

89122
const allIdEntries = Object.keys(discloseIndices).map(

sdk/core/src/utils/id.ts

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@ import { discloseIndices, revealedDataIndices } from './constants.js';
22
import { AttestationId, GenericDiscloseOutput } from 'src/types/types.js';
33
import { 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+
514
export 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,

sdk/core/src/utils/proof.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export function getRevealedDataPublicSignalsLength(attestationId: AttestationId)
1717
return 93 / 31;
1818
case 2:
1919
return Math.ceil(94 / 31);
20+
case 3:
21+
return Math.ceil(119 / 31);
2022
default:
2123
throw new ProofError(`Invalid attestation ID: ${attestationId}`);
2224
}
@@ -25,6 +27,7 @@ export function getRevealedDataPublicSignalsLength(attestationId: AttestationId)
2527
export const bytesCount: Record<AttestationId, number[]> = {
2628
1: [31, 31, 31],
2729
2: [31, 31, 31, 1],
30+
3: [31, 31, 31, 26],
2831
};
2932

3033
/**

sdk/sdk-go/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type VcAndDiscloseProof struct {
1616

1717
// VerificationConfig represents the configuration for verification
1818
type VerificationConfig struct {
19-
MinimumAge int `json:"minimumAge,omitempty"`
19+
MinimumAge int `json:"minimumAge,omitempty"`
2020
ExcludedCountries []common.Country3LetterCode `json:"excludedCountries,omitempty"`
21-
Ofac bool `json:"ofac,omitempty"`
21+
Ofac bool `json:"ofac,omitempty"`
2222
}
2323

2424
// IsValidDetails contains the validation results

0 commit comments

Comments
 (0)