@openpassport/sdk
v0.1.8
Published
```bash yarn add @openpassport/sdk ```
Downloads
60
Keywords
Readme
Installation
yarn add @openpassport/sdk
Generate a QR code
Create an AppType type object:
import { AppType } from '@openpassport/sdk';
const appName = '🤠 Cowboy App';
const scope = 'cowboyApp';
const userID = 'user1234';
const sessionID = crypto.randomUUID();
const cowboyApp: AppType = {
name: appName,
scope,
userId: userID,
sessionId,
circuit: 'prove',
arguments: {
disclosureOptions: { older_than: '18', nationality: 'France' },
},
};
| Parameter | Optional | Description |
| ----------- | -------- | ------------------------------------------------------------- |
| scope
| M | The scope of your application, is unique for each application |
| name
| M | Name of the application |
| userId
| M | User ID |
| sessionId
| M | Session ID |
| circuit
| M | Circuit to use, only prove
is available for now |
| arguments
| O | optional disclosure options, based on passport attributes |
Display the QR code
Use the appType object defined above to generate a QR code.
The generated QR code is an HTML element
that you can display in your app.
import { QRCodeGenerator } from '@openpassport/sdk';
// [...] define cowboyApp as described above
const qrCode: HTMLElement = await QRCodeGenerator.generateQRCode(cowboyApp);
Verify the proof
1 Step flow
To use the OpenPassport1StepVerifier
, import and initialize it as follows:
import { OpenPassport1StepVerifier } from '@openpassport/sdk';
const verifier = new OpenPassport1StepVerifier({
scope: 'cowboyApp',
requirements: [
['older_than', '18'],
['nationality', 'France'],
],
});
Parameters for OpenPassport1StepVerifier
| Parameter | Optional | Description |
| --------------- | -------- | --------------------------------------------------------------------------------- |
| scope
| M | The scope of your application, is unique for each application. |
| attestationId
| O | The ID of the attestation, defaults to PASSPORT_ATTESTATION_ID
. |
| requirements
| O | An array of requirements, each an array with an attribute and its expected value. |
| rpcUrl
| O | The RPC URL to connect to the blockchain, defaults to DEFAULT_RPC_URL
. |
| dev_mode
| O | Allow users with generated passport to pass the verification. |
Verify the proof
The function fired from the OpenPassport app will send a OpenPassport1StepInputs
object.
const result: OpenPassportVerifierReport = await verifier.verify(openPassport1StepInputs);
From the result
object, you can inspect the validity of any submitted attribute.
To check the overall validity of the proof, you can inspect the valid
attribute.
require(result.valid);
Nullifier and user identifier are accessible from the result
object.
const nullifier: number = result.nullifier;
const user_identifier: number = result.user_identifier;
2 Steps flow
🚧 Work in progress 🚧
Development
Install the dependencies
yarn install-sdk
Tests
To run the tests, you need to download the circuits and the zkey files from the AWS s3 bucket. This script will also compile the circuits to generate the wasm files. Make sure that the circuits in the circuits folder are up to date with the AWS zkey files.
yarn download-circuits
Then run the tests with the following command:
yarn test