# SignMessage（签名消息）

在连接至 Backpack 后，应用可以请求用户签署一条消息。

应用可自行创建消息，Backpack 在提示签名时会将该消息展示给用户。消息签名不涉及网络费用，是应用验证地址归属权的一种便捷方式。

要发送消息请求用户签名，应用应执行以下操作：

1. 提供一段以 **Hex** 或 **UTF-8** 编码的字符串，先转换为 `Uint8Array`，再用 base58 编码；
2. 请求用户通过 Backpack 钱包对该编码后的消息进行签名。

有关如何验证消息签名的更多信息，请参阅[Encryption Resources](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi.md#jia-mi-zi-yuan-encryption-resources)。

## **基础 URL**

```
https://backpack.app/ul/v1/signMessage
```

## **查询字符串参数**

* `dapp_encryption_public_key`（必填）：应用端用于当前[connect](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/connect-lian-jie.md)（连接）会话的原始加密公钥。
* `nonce`（必填）：用于加密请求的 base58 编码随机数。
* `redirect_link`（必填）：操作完成后，Backpack 应将用户重定向至该 URI。请参阅[Specifying Redirects](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/specifying-redirects-zhi-ding-zhong-ding-xiang.md)了解更多信息。需进行 URL 编码。
* `payload`（必填）：加密的 JSON 字符串，包含以下字段：

```json
{
  "message": "...", // 待签名的消息，base58 编码
  "session": "...", // 来自 connect 方法的 token
  "display": "utf8" | "hex" // 展示给用户时的编码方式，默认值为 utf8
}
```

* **`message`** (必填)：需要由用户签名的消息，以 base58 编码。当系统提示用户签名时，Backpack 会向用户显示此消息。
* `session` (必填)：从 [Connect ](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/connect-lian-jie.md)方法接收到的会话令牌。更多详情请参阅 Handling Sessions。
* `display` (必填)：您希望我们如何向用户显示该字符串。默认为 **utf8**。

## **返回值**

### Approve（同意）

* `nonce`：用于加密响应的 base58 编码随机数。
* `data`：加密的 JSON 字符串。请参考[Encryption](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi.md)部分了解如何通过共享密钥解密。加密内容以 base58 编码。

```json
// 解密后的 `data` 参数内容
{
  signature: "...", // 消息签名，base58 编码
}
```

* **`signature`**：消息签名，以 base58 编码。有关如何验证消息签名的更多信息，请参阅 [Encryption Resources](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/encryption-jia-mi-ji-zhi.md#jia-mi-zi-yuan-encryption-resources)。

### Reject（拒绝）

错误情况会以 `errorCode` 和 `errorMessage` 作为查询参数返回。

请参阅[ Errors](/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/limitations-xian-zhi.md#errors-cuo-wu-chu-li) 了解所有可能的错误代码。

```json
{
  "errorCode": "...",
  "errorMessage": "..."
}
```

***


---

# 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://support.backpack.exchange/support-docs/cn/qian-bao/ji-shu-wen-dang/deeplinks/provider-fang-fa/signmessage-qian-ming-xiao-xi.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.
