# DID

## **DID Login Process**

### 1  Check if the address has a DID

```dart
 final client = Provider.of<Client>(context, listen: false);
 SDNDIDListResponse response = await client.getDIDList(address: address);
```

Input Parameters:

| Name    | Type   | Description    | Required |
| ------- | ------ | -------------- | -------- |
| address | String | wallet address | true     |

Output Parameters:

`SDNDIDListResponse`

| Name | Type   | Description  | Required |
| ---- | ------ | ------------ | -------- |
| data | String | List of DIDs | true     |

### 2   Log into a DID or register an address.&#x20;

Choose DID or use the address to log in. If the interface array is empty, log in with the address. Otherwise, use the first element of the array as the 'did' parameter.

```dart
 final client = Provider.of<Client>(context, listen: false);
 String responseStr;
 if (response1.data.isNotEmpty) {
   responseStr = await client.postPreLoginDID(DID: response1.data[0]);
 } else {
   responseStr = await client.postPreLoginDID(address: address);
 }
```

Input Parameters:

| Name    | Type   | Description                                         | Required |
| ------- | ------ | --------------------------------------------------- | -------- |
| DID     | String | DID string, choose either DID or wallet address     | False    |
| address | String | wallet address, choose either DID or wallet address | False    |

Output Parameters:  `PreloginResponse`

| Name           | Type   | Description                         | Required |
| -------------- | ------ | ----------------------------------- | -------- |
| DID            | String | user DID (existed or newly created) | true     |
| message        | String | message to be signed                | true     |
| updated        | String | update time                         | true     |
| random\_server | string | nounce returned from the node       | true     |

### 3  Sign the message that was returned in step 2

```dart
    String str = responsesdn.message; //responsesdn.message
    String signMessage = EthSigUtil.signPersonalMessage(
    privateKey: privKey, message: convertStringToUint8List(str));
```

Input Parameters: `LoginRequest`

| Name       | Type            | Description                                        | Required |
| ---------- | --------------- | -------------------------------------------------- | -------- |
| type       | String          | Login type (current value: `m.login.did.identity`) | true     |
| updated    | String          | update time returned by the `pre_login`            | true     |
| identifier | IdentifierModel | login information                                  | true     |
| device\_id | String          | device id, no need for new device                  | false    |

`IdentifierModel` Type:

| Name  | Type   | Description                                                                                                                                          |
| ----- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| DID   | String | User DID                                                                                                                                             |
| token | String | To sign the message returned by `pre_login`, you can call the `EthSigUtil.signPersonalMessage` function from the DID class to perform the signature. |

Output Parameters:

`SDNDIDLoginResponse`

| Name          | Type   | Description  | Required |
| ------------- | ------ | ------------ | -------- |
| access\_token | String | access token | true     |
| user\_id      | String | user ID      | true     |
| device\_id    | String | device id    | true     |
|               |        |              |          |

### 4  Log out

```dart
 Future<void> logout() async {
  try {
    await super.logout();
  } catch (e, s) {
    Logs().e('Logout failed', e, s);
    rethrow;
  } finally {
    await clear();
  }
}
```

Input Parameters:

| Name  | Type   | Description                                        | Required |
| ----- | ------ | -------------------------------------------------- | -------- |
| token | String | Login type (current value: `m.login.did.identity`) | true     |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sending-network.gitbook.io/sending.network/sdk-documentation/flutter-sdk/did.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
