mirror of
https://github.com/selfxyz/self.git
synced 2026-04-27 03:01:15 -04:00
Merge pull request #242 from zk-passport/sdk/disclose-country
allow users to disclose nationality
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -39,4 +39,4 @@
|
||||
"@types/node-forge": "^1.3.10",
|
||||
"prettier": "^3.3.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +352,7 @@ export function getCountryCode(countryName: string): string | string {
|
||||
return found ? found[0] : 'undefined';
|
||||
}
|
||||
export const countryNames = [
|
||||
'Any',
|
||||
"Afghanistan",
|
||||
"Aland Islands",
|
||||
"Albania",
|
||||
|
||||
@@ -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);
|
||||
|
||||
4452
common/yarn.lock
4452
common/yarn.lock
File diff suppressed because it is too large
Load Diff
@@ -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",
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
1
sdk/qrcode/.yarnrc.yml
Normal file
1
sdk/qrcode/.yarnrc.yml
Normal file
@@ -0,0 +1 @@
|
||||
nodeLinker: node-modules
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -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",
|
||||
@@ -84,4 +84,4 @@
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
sdk/tests/web-app/.yarnrc.yml
Normal file
1
sdk/tests/web-app/.yarnrc.yml
Normal file
@@ -0,0 +1 @@
|
||||
nodeLinker: node-modules
|
||||
@@ -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",
|
||||
@@ -29,4 +29,4 @@
|
||||
"tailwindcss": "^3.4.1",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user