# API Reference

## Index

* [createAuthRequest](#createauthrequest)
* [createSignData](#createsigndata)
* [requestQR](#requestqr)
* [queryQRResult](#queryqrresult)[  ](#cancelqueryqrresult)
* [cancelQueryQRResult](#cancelqueryqrresult)

## createAuthRequest

Creates`AuthRequest` to get the authentication challenge message.

#### Parameters&#x20;

| Parameter | Type   | Description                      |
| --------- | ------ | -------------------------------- |
| `action`  | `enum` | IdAuth: = 0 IdAuthAndVcAuth: = 1 |

#### **Returns**

[`AuthRequest`](https://docs.ont.io/decentralized-identity-and-data/ontid/protocol-specification#authentication-request)

## createSignData

Creates a message for the user to sign with the wallet.

{% hint style="info" %}
Convert the message to a JSON string before signing.
{% endhint %}

#### Parameters&#x20;

| Parameter       | Type            | Description                                                                                                                    |
| --------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| `AuthChallenge` | `AuthChallenge` | See details [here](https://docs.ont.io/decentralized-identity-and-data/ontid/protocol-specification#authentication-challenge). |
| `account`       | `string`        | DID of the signer (user).                                                                                                      |

#### Returns&#x20;

[`SignData`](https://docs.ont.io/decentralized-identity-and-data/ontid/protocol-specification#signature-and-authorization)

## requestQR

Gets the challenge in the form of a QR code with `AuthChallenge`.

#### **Parameters**

[`AuthChallenge`](https://docs.ont.io/decentralized-identity-and-data/ontid/protocol-specification#authentication-challenge)

#### **Returns**

`Promise<QrResult>` **,** including the following properties:

| Property | Type     | Description                      |
| -------- | -------- | -------------------------------- |
| `id`     | `string` | QR code ID.                      |
| `text`   | `string` | Text for generating the QR code. |

## `queryQRResult`

Fetches the result of a user scanning the QR code.&#x20;

The query loops until a result or an error is returned. To stop the query, call [`cancelQueryQRResult`](#cancelqueryqrresult).

#### **Parameters**

| Property   | Type     | Description                                                       | Required |
| ---------- | -------- | ----------------------------------------------------------------- | -------- |
| `id`       | `string` | QR code ID.                                                       | Yes      |
| `duration` | `number` | Time interval between two queries, in milliseconds. Default: 1000 | No       |

#### **Returns**

[`Promise<ChallengeResponse>`](https://docs.ont.io/decentralized-identity-and-data/ontid/protocol-specification#authentication-response)

## cancelQueryQRResult

Stops querying the result of a QR code scan.

#### **Parameters**

None

#### **Returns**

`void`

## Errors

| Member              | Value                      |
| ------------------- | -------------------------- |
| `VersionNotSupport` | `ERR_WRONG_VERSION`        |
| `TypeNotSupport`    | `ERR_TYPE_NOT_SUPPORTED`   |
| `ActionNotSupport`  | `ERR_ACTION_NOT_SUPPORTED` |
| `UserCanceled`      | `USER_CANCELED`            |
| `UnknownError`      | `ERR_UNDEFINED`            |
