Skip to content

Commit

Permalink
Merge pull request #242 from zk-passport/sdk/disclose-country
Browse files Browse the repository at this point in the history
allow users to disclose nationality
  • Loading branch information
remicolin authored Nov 2, 2024
2 parents 0fe0881 + f58ac83 commit a2f9340
Show file tree
Hide file tree
Showing 13 changed files with 3,005 additions and 1,712 deletions.
4 changes: 3 additions & 1 deletion app/src/screens/ProveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ const ProveScreen: React.FC<ProveScreenProps> = ({ setSheetRegisterIsOpen }) =>
case 'minimumAge':
return `I am older than ${option.value} years old.`;
case 'nationality':
return `I have a valid passport from ${option.value}.`;
return option.value === 'Any'
? `The issuer country of my passport.`
: `I have a valid passport from ${option.value}.`;
case 'excludedCountries':
return option.value.length > 0
? `I am not part of the following countries: ${option.value
Expand Down
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"@types/node-forge": "^1.3.10",
"prettier": "^3.3.3"
}
}
}
1 change: 1 addition & 0 deletions common/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export function getCountryCode(countryName: string): string | string {
return found ? found[0] : 'undefined';
}
export const countryNames = [
'Any',
"Afghanistan",
"Aland Islands",
"Albania",
Expand Down
8 changes: 8 additions & 0 deletions common/src/utils/openPassportAttestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ export class OpenPassportDynamicAttestation implements OpenPassportAttestation {
return (parsedPublicSignals as any).commitment;
}
}

getNationality(): string {
const parsedPublicSignals = this.parsePublicSignals();
const revealedData_packed = (parsedPublicSignals as any).revealedData_packed;
const unpackedReveal = unpackReveal(revealedData_packed);
return getAttributeFromUnpackedReveal(unpackedReveal, 'nationality');
}

getCSCAMerkleRoot(): string {
if (this.dscProof.value.publicSignals) {
const parsedPublicSignalsDsc = parsePublicSignalsDsc(this.dscProof.value.publicSignals);
Expand Down
4,658 changes: 2,964 additions & 1,694 deletions common/yarn.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sdk/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openpassport/core",
"version": "0.0.7",
"version": "0.0.9",
"main": "dist/sdk/core/index.js",
"types": "dist/sdk/core/index.d.ts",
"license": "MIT",
Expand Down
8 changes: 6 additions & 2 deletions sdk/core/src/AttestationVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ export class AttestationVerifier {
}
}
if (this.nationality.enabled) {
const attributeValue = getAttributeFromUnpackedReveal(unpackedReveal, 'nationality');
this.verifyAttribute('nationality', countryCodes[attributeValue], this.nationality.value);
if (this.nationality.value === 'Any') {
console.log('\x1b[32m%s\x1b[0m', '- nationality verified');
} else {
const attributeValue = getAttributeFromUnpackedReveal(unpackedReveal, 'nationality');
this.verifyAttribute('nationality', countryCodes[attributeValue], this.nationality.value);
}
}
if (this.ofac) {
const attributeValue = parsedPublicSignals.ofac_result.toString();
Expand Down
5 changes: 5 additions & 0 deletions sdk/core/src/OpenPassportVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class OpenPassportVerifier extends AttestationVerifier {
return this;
}

discloseNationality(): this {
this.setNationality('Any');
return this;
}

excludeCountries(...countries: (typeof countryNames)[number][]): this {
this.excludedCountries = { enabled: true, value: countries };
return this;
Expand Down
1 change: 1 addition & 0 deletions sdk/qrcode/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
12 changes: 6 additions & 6 deletions sdk/qrcode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openpassport/qrcode",
"version": "0.0.8",
"version": "0.0.12",
"main": "dist/sdk/qrcode/index.js",
"types": "dist/sdk/qrcode/index.d.ts",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"author": "turnoffthiscomputer",
"dependencies": {
"@openpassport/core": "0.0.7",
"@openpassport/core": "0.0.9",
"@types/react": "^18.3.4",
"@types/react-dom": "^18.3.0",
"@types/uuid": "^10.0.0",
Expand All @@ -36,6 +36,9 @@
"zlib": "^1.0.5"
},
"devDependencies": {
"@openpassport/zk-kit-imt": "^0.0.5",
"@openpassport/zk-kit-lean-imt": "^0.0.6",
"@openpassport/zk-kit-smt": "^0.0.1",
"@types/chai": "^4.3.6",
"@types/chai-as-promised": "^7.1.8",
"@types/circomlibjs": "^0.1.6",
Expand All @@ -45,9 +48,6 @@
"@types/node-forge": "^1.3.5",
"@types/pako": "^2.0.3",
"@types/snarkjs": "^0.7.8",
"@openpassport/zk-kit-imt": "^0.0.5",
"@openpassport/zk-kit-lean-imt": "^0.0.6",
"@openpassport/zk-kit-smt": "^0.0.1",
"asn1js": "^3.0.5",
"axios": "^1.7.2",
"chai": "^4.3.8",
Expand Down Expand Up @@ -84,4 +84,4 @@
"react": "^18.0.0",
"react-dom": "^18.0.0"
}
}
}
1 change: 1 addition & 0 deletions sdk/tests/web-app/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
6 changes: 3 additions & 3 deletions sdk/tests/web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/material": "^6.0.2",
"@openpassport/core": "^0.0.7",
"@openpassport/qrcode": "^0.0.8",
"@openpassport/core": "^0.0.9",
"@openpassport/qrcode": "^0.0.12",
"axios": "^1.7.7",
"next": "14.2.8",
"react": "^18",
Expand All @@ -29,4 +29,4 @@
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
}
9 changes: 5 additions & 4 deletions sdk/tests/web-app/src/app/prove/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import OpenPassportQRcode from '../../../../../qrcode/OpenPassportQRcode';
import { v4 as uuidv4 } from 'uuid';
import { OpenPassportVerifier } from '@openpassport/core';
import { OpenPassportVerifier, OpenPassportDynamicAttestation } from '@openpassport/core';
export default function Prove() {
const userId = uuidv4();
const scope = 'scope';

const openPassportVerifier: OpenPassportVerifier = new OpenPassportVerifier('prove_offchain', scope)
.excludeCountries('Finland', 'Norway')
.allowMockPassports()
.setMinimumAge(12);
.discloseNationality()
.allowMockPassports();
return (
<div className="h-screen w-full bg-white flex flex-col items-center justify-center gap-4">
<OpenPassportQRcode
Expand All @@ -19,6 +18,8 @@ export default function Prove() {
userIdType={'uuid'}
openPassportVerifier={openPassportVerifier}
onSuccess={(attestation) => {
const dynamicAttestation = new OpenPassportDynamicAttestation(attestation);
console.log('nationality:', dynamicAttestation.getNationality());
// send the code to the backend server
}}
/>
Expand Down

0 comments on commit a2f9340

Please sign in to comment.