# DID

## 1. Check if an Address has a SendingNetwork DID

```objectivec
- (MXHTTPOperation *)getDIDList:(NSString *)address
                        success:(void (^) (MXDIDListResponse *response))success
                        failure:(void (^)(NSError *error))failure ;
```

**Input Parameters**:

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

**Output Parameters**:

`MXDIDListResponse`

| Name  | Type     | Description  | Required |
| ----- | -------- | ------------ | -------- |
| array | NSString | list of DIDs | False    |

## 2. Log into a DID or Register an Address

If the returned array is empty, log in using the wallet address; otherwise, use the first element of the array as the 'did' parameter.

```objectivec
- (MXHTTPOperation *)postPreLoginDID:(NSString *)did
                             address:(NSString*)address
                             success:(void (^) (MXPreLoginResponse *response))success
                             failure:(void (^)(NSError *error))failure;
```

**Input Parameters**:

| Name      | Type     | Description    | Required |
| --------- | -------- | -------------- | -------- |
| `address` | NSString | wallet address | false    |
| `did`     | NSString | user DID       | false    |

**Output Parameters**：

| Name            | Type     | Description                             | Required |
| --------------- | -------- | --------------------------------------- | -------- |
| `DID`           | NSString | user DID (existing or newly created)    | true     |
| `message`       | NSString | message to be signed                    | true     |
| `updated`       | NSString | update time                             | true     |
| `random_server` | NSString | random number generated by the DID node | true     |

## 3. Sign the Message Returned

```objectivec
- (MXHTTPOperation *)postLoginDID:(NSString *)did
                     withParameter:(NSDictionary *)parameter
                     success:(void (^) (MXDIDLoginResponse *response))success
                     failure:(void (^)(NSError *error))failure {
```

**Input Parameters**: `parameter`

<table><thead><tr><th>Name</th><th width="153">Type</th><th width="311">Description</th><th>Required</th></tr></thead><tbody><tr><td>type</td><td>NSString</td><td>Login type (e.g., <code>m.login.did.identity</code>)</td><td>true</td></tr><tr><td>updated</td><td>NSString</td><td>update time returned by the <code>pre_login</code></td><td>true</td></tr><tr><td>identifier</td><td>IdentifierModel</td><td>login information</td><td>true</td></tr><tr><td>device_id</td><td>NSString</td><td>device id, not needed for a new device</td><td>false</td></tr><tr><td>random_server</td><td>NSString</td><td>returned by postPreLoginDID</td><td>true</td></tr></tbody></table>

`IdentifierModel` Type:

| Name  | Type     | Description                                            |
| ----- | -------- | ------------------------------------------------------ |
| did   | NSString | user DID                                               |
| token | NSString | Token used to sign the message returned by `pre_login` |

**Output Parameters**:

`MXDIDLoginResponse`

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

***

{% hint style="warning" %}
The login process and APIs described below are deprecated. Please avoid using them.
{% endhint %}

## (Deprecated) DID login process:

1. Get DID list. If the list is empty, register a decentralized identity. Otherwise, call `pre_login` in step 4 to log in to an existing DID.
2. Create a DID document with the current wallet address by calling the `DIDCreate` method.
3. Sign the message returned in step 2 and call the `DIDSave` method.
4. Call `pre_login` to get the message to be signed.
5. Sign the message returned in step 4 and use the signature to log in to DID with `postLoginDID` method.

## (Deprecated) **Get DID list**

```swift
client?.getDIDInfo(wallet, success: { <#MXDIDListInfoResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name      | Type   | Description    | Required |
| --------- | ------ | -------------- | -------- |
| `address` | string | Wallet address | true     |

Returns：

| Name       | Type         | Description   | Required |
| ---------- | ------------ | ------------- | -------- |
| `response` | string array | User DID list | true     |

## (Deprecated) **Get DID information**

```swift
client?.getDIDInfo(wallet, success: { <#MXDIDListInfoResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name  | Type   | Description                               | Required |
| ----- | ------ | ----------------------------------------- | -------- |
| `DID` | string | DID string from the `getDIDInfo(address)` | true     |

Returns：

| Name                 | Type   | Description                 | Required |
| -------------------- | ------ | --------------------------- | -------- |
| `controllers`        | Json   | controller information      | true     |
| `current_public_key` | string | current device's public key | true     |
| `public_keys`        | Json   | public key information      | true     |

`controllers` and `public_keys` type：

| Name     | Type   | Description                                                     |
| -------- | ------ | --------------------------------------------------------------- |
| `type`   | string | `EcdsaSecp256k1RecoveryMethod2020/``Ed25519VerificationKey2018` |
| `value`  | string | wallet address or public key                                    |
| `key_id` | string | public key id                                                   |

## (Deprecated) **Create DID**

```swift
client?.postCreateDID(address, success: { <#MXCreateDIDResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name      | Type   | Description                                                | Required |
| --------- | ------ | ---------------------------------------------------------- | -------- |
| `address` | string | wallet address with blockchain information like `eip155:1` | true     |

Returns：

| Name      | Type   | Description                          | Required |
| --------- | ------ | ------------------------------------ | -------- |
| `DID`     | string | user DID (existing or newly created) | true     |
| `message` | string | message to be signed                 | true     |
| `updated` | string | update time                          | true     |

## (Deprecated) **Save DID information**

```swift
client?.postSaveDID(did, withParameter: ["signature":"","operation":"create","updated":updateTime], success: { <#MXSaveDIDResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name  | Type   | Description | Required |
| ----- | ------ | ----------- | -------- |
| `DID` | string | DID string  | true     |

Parameters:

| Name        | Type         | Description                                                                                 | Required |
| ----------- | ------------ | ------------------------------------------------------------------------------------------- | -------- |
| `signature` | string       | sign the message with *web3.eth.personal.sign* method                                       | true     |
| `operation` | string       | create, link, unlink, link\_key, unlink\_key                                                | true     |
| `ids`       | string array | the DID URL of unlink, unlink\_key; unnecessary in create， link, link\_publick operation    | false    |
| `address`   | string       | wallet address (with blockchain-specific prefix, e.g., eip155:1 ) in link, create operation | true     |
| `updated`   | string       | updated time returned by `postCreateDID(address)`                                           | true     |

Message Prefix

| operation          | Type   | Message                     |
| ------------------ | ------ | --------------------------- |
| `create`           | string | `Create an account\n`       |
| `link`             | string | `Add new address\n`         |
| `link_key`         | string | `Login with this account\n` |
| `unlink/unlin_key` | string | `Unlink this address\n`     |
| `burn`             | string | `Burn this account\n`       |

## (Deprecated) **Update DID**

```swift
client?.postUpdateDID(did, withParameter: ["operation":"link"], success: { <#MXUpdateDIDResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name  | Type   | Description | Required |
| ----- | ------ | ----------- | -------- |
| `DID` | string | DID string  | true     |

POST Body

| Name        | Type         | Description                                                                                                                    | Required |
| ----------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------ | -------- |
| `ids`       | string array | Wallet address ID that needs to be unbound                                                                                     | false    |
| `address`   | string       | Wallet address that needs to be added. The address needs to be prefixed by blockchain specific strings like `did:pkh:eip155:1` | false    |
| `operation` | string       | link, unlink, link\_key, unlink\_key                                                                                           | true     |

Returns：

| Name      | Type   | Description                          | Required |
| --------- | ------ | ------------------------------------ | -------- |
| `did`     | string | User DID (existing or newly created) | true     |
| `message` | string | Message to be signed                 | true     |
| `updated` | string | Update time                          | true     |

## (Deprecated) **DID Pre-login**

```swift
client?.postPreLoginDID(DID, success: { <#MXPreLoginResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name  | Type   | Description | Required |
| ----- | ------ | ----------- | -------- |
| `DID` | string | DID string  | true     |

Returns：

| Name      | Type   | Description                          | Required |
| --------- | ------ | ------------------------------------ | -------- |
| `DID`     | string | User DID (existing or newly created) | true     |
| `message` | string | Message to be signed                 | true     |
| `updated` | string | Update time                          | true     |

## (Deprecated) **Log in to DID**

```swift
client?.postLoginDID(did, withParameter: ["type":" m.login.did.identity","updated":updateTime,], success: { <#MXDIDLoginResponse#> in
    <#code#>
}, failure: { <#Error#> in
    <#code#>
})
```

Parameters：

| Name         | Type   | Description                                                             | Required |
| ------------ | ------ | ----------------------------------------------------------------------- | -------- |
| `type`       | string | type of login (the type of the above example is `m.login.did.identity`) | true     |
| `updated`    | string | updated time returned by the `pre_login` method                         | true     |
| `identifier` | json   | login information                                                       | true     |
| `device_id`  | string | device id, not needed for new device                                    | false    |

identifier type：

| Name    | Type   | Description                                                                                                                                                                                        |
| ------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `DID`   | string | User DID                                                                                                                                                                                           |
| `token` | string | Sign the `message` returned by `pre_login` method and perform `base16` encoding. The signature method is *etherum.Sign(accounts.TextHash(message), privateKey)* or *personal\_sign* from Metamask. |

Returns：

| Name           | Type   | Description  | Required |
| -------------- | ------ | ------------ | -------- |
| `access_token` | string | access token | true     |
| `user_id`      | string | user id      | true     |
| `device_id`    | string | device id    | 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/ios-client-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.
