Skip to content

Commit

Permalink
Merge pull request #22 from 0xPolygonID/update-docs
Browse files Browse the repository at this point in the history
update verifier docs
  • Loading branch information
cerberushades authored Aug 24, 2023
2 parents 326b897 + e511eb1 commit 73d9d3e
Showing 1 changed file with 168 additions and 1 deletion.
169 changes: 168 additions & 1 deletion docs/verifier/verification-library/verifier-set-up.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,175 @@ The Verifier Client must fetch the Auth Request generated by the Server (`/api/s
> To display the QR code inside your frontend, you can use this [Code Sandbox](https://codesandbox.io/s/yp1pmpjo4z?file=/index.js).
The same request can also be delivered to users via Deep Linking. In order to do so, it is necessary to encode the `request` file to Base64 Format. The related deep link would be `iden3comm://?i_m={{base64EncodedRequestHere}}`.
A Verifier can show a QR code that contains one of the following data structures:
* Raw JSON - message will be treated as one of the [IDEN3 Protocol messages](https://iden3-communication.io/credentials/overview/).
* Link with base64 encoded message or shortened request URI (encoded URL) in case base64-encoded message is too large. Possible formats of links are:
1. `iden3comm://?i_m={{base64EncodedRequestHere}}`
2. `iden3comm://?request_uri={{shortenedUrl}}`


If both params are present `i_m` is prioritized and `request_uri` is ignored.

The same request can also be delivered to users via Deep Linking. The same format for links must be used.

:::note "Polygon ID wallet"

Polygon ID wallet will support handling of `request_uri` in the next release, while your client can already implement this specification.

:::

***Shortened URL algorithm***

While it's not strictly restricted how you can perform URL shortage algorithm, it is recommended to follow these instructions:
1. Generate a UUID for a particular request (or use ID of the message itself)
2. Implement an endpoint to fetch messages by UUID.
3. Encode URL to fetch messages to `the request_uri`.
Example of URL shortage logic:
<Tabs>
<TabItem value= "Golang">
```go
package handlers
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"time"
"github.com/gofrs/uuid"
"github.com/patrickmn/go-cache"
)
var cacheStorage = cache.New(60*time.Minute, 60*time.Minute)
func HandleQRData(w http.ResponseWriter, r *http.Request) {
switch r.Method {
// create url for the message
case http.MethodPost:
// get json data from request body
var data interface{}
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "Failed to read request body", http.StatusInternalServerError)
return
}
defer r.Body.Close()
err = json.Unmarshal(body, &data)
if err != nil {
http.Error(w, "Failed to unmarshal body data", http.StatusInternalServerError)
return
}
// generate random key
uv, err := uuid.NewV4()
if err != nil {
http.Error(w, "Failed to generate uuid", http.StatusInternalServerError)
return
}
// store data in map
cacheStorage.Set(uv.String(), data, 1*time.Hour)
hostURL := os.Getenv("HOST_URL") // e.g. https://verifier.com
// write key to response
fmt.Fprintf(w, "%s%s?id=%s", hostURL, "api/qr-store", uv.String())
return
// get message by identifier
case http.MethodGet:
// get path param
id := r.URL.Query().Get("id")
if id == "" {
http.Error(w, "Failed to get id", http.StatusNotFound)
return
}
// get data from map
data, ok := cacheStorage.Get(id)
if !ok {
http.Error(w, fmt.Sprintf("Failed to retrieve QR data by %s", id), http.StatusNotFound)
return
}
jsonData, err := json.Marshal(data)
if err != nil {
http.Error(w, "Failed to encode JSON", http.StatusInternalServerError)
return
}
// write data to response
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.Write(jsonData)
return
}
}
```
</TabItem>
<TabItem value= "Javascript">
```js
const express = require('express');
const { v4: uuidv4 } = require('uuid');
const Cache = require('cache-manager');
const HttpStatus = require('http-status-codes');
const app = express();
app.use(express.json());
const cPromise = Cache.caching('memory', {
max: 100,
ttl: 10 * 1000 /*milliseconds*/,
});
app.get('/api/qr-store', async (req, res) => {
const id = req.query.id;
const cacheManager = await cPromise;
const data = await cacheManager.get(id);
if (!data) {
return res.status(HttpStatus.NOT_FOUND).json({ error: `item not found ${id}` });
}
return res.status(HttpStatus.OK).json(data);
});
app.post('/api/qr-store', async (req, res) => {
const body = req.body;
const uuid = uuidv4();
const cacheManager = await cPromise;
console.log(cacheManager);
await cacheManager.set(uuid, body, { ttl: 3600 });
const hostUrl = process.env.HOST_URL;
const qrUrl = `${hostUrl}/api/qr-store?id=${uuid}`;
return res.status(HttpStatus.OK).json({ qrUrl });
});
app.listen(3000, () => {
console.log('Express server is running on port 3000');
});
```
</TabItem>
</Tabs>
**Implement Further Logic**
This tutorial showcased a minimalistic application that leverages Polygon ID libraries for authentication purposes. Developers can leverage the broad set of existing Credentials held by users to set up any customized Query using our [ZK Query Language](./zk-query-language.md) to unleash the full potential of the framework.
Expand Down

0 comments on commit 73d9d3e

Please sign in to comment.