diff --git a/sdk/README.md b/sdk/README.md index c59174b6..79b199c9 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -4,7 +4,53 @@ yarn add @openpassport/sdk ``` -# How to use +# Generate a QR code + +### Create an AppType type object: +```typescript + +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. +```typescript +import { QRCodeGenerator} from '@openpassport/sdk'; + +// [...] define cowboyApp as described above + +const qrCode : HTMLElement = await QRCodeGenerator.generateQRCode(cowboyApp); +``` + + + +# Verify the proof ## 1 Step flow @@ -13,7 +59,7 @@ To use the `OpenPassport1StepVerifier`, import and initialize it as follows: ```typescript import { OpenPassport1StepVerifier } from '@openpassport/sdk'; const verifier = new OpenPassport1StepVerifier({ - scope: 'yourScope', + scope: 'cowboyApp', requirements: [ ['older_than', '18'], ['nationality', 'France'], @@ -21,27 +67,44 @@ const verifier = new OpenPassport1StepVerifier({ }); ``` -### parameters for `OpenPassport1StepVerifier` +### Parameters for `OpenPassport1StepVerifier` | Parameter | Optional | Description | | --------------- | -------- | --------------------------------------------------------------------------------- | -| `scope` | No | The scope of your application, is unique for each application. | -| `attestationId` | Yes | The ID of the attestation, defaults to `PASSPORT_ATTESTATION_ID`. | -| `requirements` | Yes | An array of requirements, each an array with an attribute and its expected value. | -| `rpcUrl` | Yes | The RPC URL to connect to the blockchain, defaults to `DEFAULT_RPC_URL`. | +| `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. + +```typescript +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. + +```typescript +require(result.valid); +``` -Finally, verify the proof: -The function fired from the OpenPassport app will send a `OpenPassportWeb2Inputs` object. +Nullifier and user identifier are accessible from the `result` object. ```typescript -const result = await verifier.verify(openPassportWeb2Inputs); // OpenPassportWeb2Inputs : OpenPassportWeb2Inputs +const nullifier : number = result.nullifier; +const user_identifier : number = result.user_identifier; ``` + ## 2 Steps flow ### 🚧 Work in progress 🚧 # Development +Install the dependencies ```bash yarn install-sdk