Skip to content

Commit 786a104

Browse files
Use the new react lib in the proof of citizenship guide (#66)
* Use the new react lib in the proof of citizenship guide * Applied review feedback * Apply more feedback * event_id fix
1 parent de191b7 commit 786a104

2 files changed

Lines changed: 58 additions & 46 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
### Fixed
1212
- Fixed the link to the verifier instance in the proof of citizenship guide;
1313

14+
### Changed
15+
- Use the new lib for React in the proof of citizenship guide;
16+
1417
## [5.8.2] - 2025-04-08
1518
### Fixed
1619
- Link to Noir verifiers.

docs/zk-passport/guide-proof-of-citizenship.mdx

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Basically, it goes likes this:
1919
4. The app submits the proof to the callback URL(specified in the QR code) for verification
2020
5. DApp backend fetches the verification status and citizenship data from a REST API
2121

22+
QR code generation and all the interactions with the backend are facilitated by Rarimo's ZK Passport library, which is available as an NPM package: `@rarimo/zk-passport`. The library provides a convenient API for generating QR codes and verifying the proof status.
23+
2224
You can check out this flow in the sandbox: <OutLink href="https://app.rarime.com/proof-requests-demo">ZK Passport Demo</OutLink>
2325

2426
## Pre-requisites
@@ -40,65 +42,68 @@ Links for installation:
4042
- <OutLink href="https://apps.apple.com/us/app/rarime/id6503300598">RariMe for iOS | AppStore</OutLink>
4143
- <OutLink href="https://play.google.com/store/apps/details?id=com.rarilabs.rarime">RariMe for Android | Google Play</OutLink>
4244

43-
## Step #2: Render a QR code with a verification request in your app
45+
## Step #2: Install `@rarimo/zk-passport-react` package
4446

45-
To request data for the QR code, you need to call this endpoint on the `verificator-svc`:
46-
<OutLink href="https://api.app.rarime.com/integrations/verificator-svc/private/verification-link">https://api.app.rarime.com/integrations/verificator-svc/private/verification-link</OutLink>
47+
To install the package, run the following command in your project directory:
4748

48-
The following JS snippet gets data for a QR code for a passport verification with a uniqueness check on:
49+
```bash npm2yarn
50+
npm install @rarimo/zk-passport-react
51+
```
4952

50-
```jsx
51-
const verificatorUrl = 'https://api.app.rarime.com/' // your verificator-svc instance URL
52-
const body = {
53-
data: {
54-
type: "user",
55-
// Some public and unique user ID
56-
// Will be used to fetch status later
57-
id: "some-user-id",
58-
attributes: {
59-
// Denotes the application and activity that is requesting the verification
60-
event_id: "citizenship_verification",
61-
// Let a single passport pass verification just once
62-
uniqueness: true
63-
}
64-
}
65-
}
53+
If you don't use React, you can use the `@rarimo/zk-passport` package instead. It provides a low-level API for for requesting and passing for verification of ZK Passport proofs.
6654

67-
const response = await fetch(
68-
69-
`${verificatorUrl}/integrations/verificator-svc/private/verification-link`,
70-
{
71-
headers: {
72-
'Accept': 'application/vnd.api+json',
73-
'Content-Type': 'application/vnd.api+json',
74-
},
75-
method: "POST",
76-
body: JSON.stringify(body),
77-
}
78-
)
79-
const { data } = await response.json()
80-
// Proof Params URL for RariMe app
81-
const proofParamsUrl = data.attributes.get_proof_params
82-
const encodedUrl = encodeURIComponent(proofParamsUrl)
83-
// Render this data in a QR code:
84-
const qrCodeContent = `rarime://external?type=proof-request&proof_params_url=${encodedUrl}`)
55+
```bash npm2yarn
56+
npm install @rarimo/zk-passport
8557
```
8658

87-
Some notes:
59+
## Step #3: Import the library and render the QR code
60+
61+
The following JS snippet uses the library to render a QR code with a proof of citizenship request and handles the results:
8862

89-
- `event_id` is an arbitrary string that denotes the application scope of the proof, should be something like `APP_ID:ACTION_ID`
90-
- `id` is a public unique ID associated with a user within your system. It will be used in Step #3 to check the user status
63+
```jsx
64+
import ZkPassportQrCode from '@rarimo/zk-passport-react'
9165

92-
After scanning the QR code, the user will complete the verification in RariMe App.
66+
// this is a public instance of verificator-svc(https://github.com/rarimo/verificator-svc). Replace it with the URL of your instance
67+
const apiUrl = 'https://api.app.rarime.com'
9368

94-
## Step #3: Check the user status
69+
// `requestid` is a public unique ID associated with a user within your system. It will be used in the Step #3 to check the user status
70+
const requestId = 'account-1'
9571

96-
You can fetch the verification status for a particular `id` from this endpoint:
72+
// `event_id` is an arbitrary number that denotes the application scope of the proof
73+
const eventId = 1337
74+
75+
const verificationOpts: RequestVerificationLinkOpts = {
76+
uniqueness: true, // check if the user has already passed the verification
77+
nationalityCheck: true, // include user's citizenship in the output(proof public signals)
78+
eventId: eventId, // scope of the proof
79+
}
80+
81+
return (
82+
<ZkPassportQrCode
83+
// Proof request params
84+
apiUrl={apiUrl}
85+
requestId={requestId}
86+
verificationOptions={verificationOpts}
87+
88+
// QR code component props
89+
qrProps={{ size: 256 }}
90+
91+
// place your callbacks here
92+
onStatusChange={status => console.log(status)}
93+
onSuccess={proof => console.log(proof)}
94+
onError={error => console.error(error)}
95+
/>
96+
)
97+
```
98+
99+
## Step #3: Fetch the verification status and the citizenship code on the backend
100+
101+
You can fetch the verification status for a particular `id` from this verificator endpoint:
97102
<OutLink href="https://rarimo.github.io/verificator-svc/#tag/User-verification/operation/getUserStatus">https://rarimo.github.io/verificator-svc/#tag/User-verification/operation/getUserStatus</OutLink>
98103

99104
Here is a JS snippet for doing this
100105

101-
```jsx
106+
```ts
102107
const backendUrl = 'https://api.app.rarime.com/'
103108
const userId = 'some-user-id' // the `id` from step #2
104109

@@ -118,11 +123,15 @@ const verificationStatus = data.attributes.status
118123

119124
If the user has status `verified`, you can fetch the verified citizenship code like this:
120125

121-
```jsx
126+
```ts
122127
const response = await fetch(`${backendUrl}/integrations/verificator-svc/private/user/${userId}`)
123128
const { data } = await response.json()
124129

125130
// ISO 3166 alpha-3 country code: https://www.iban.com/country-codes
126131
// Note: German passports may have a single-letter "D" code
127132
const citizenshipISOCode = data.attributes.nationality // e.g. "UKR"
128133
```
134+
135+
## Conclusion
136+
137+
In this guide, we set up off-chain citizenship verification using ZK Passport and the RariMe App, enabling secure proof of citizenship without exposing private user data.

0 commit comments

Comments
 (0)