> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lasersell.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 钱包注册

> 使用 Ed25519 所有权证明将钱包注册到退出智能流。

## 概述

钱包注册向 LaserSell API 证明你拥有某个 Solana 钱包。在连接钱包到退出智能流之前需要进行注册。流会验证 `configure` 消息中的每个钱包都已注册到你的账户。

注册使用 Ed25519 签名，因此无需链上交易。

## `POST /v1/wallets/register`

通过 Ed25519 签名证明所有权来注册钱包。

### 请求

```json theme={null}
{
  "wallet_pubkey": "YourWalletPubkey...",
  "signature": "base58-encoded-ed25519-signature",
  "message": "lasersell-register:YourWalletPubkey...:1706000000",
  "label": "My Trading Wallet"
}
```

| 字段              | 类型       | 必需 | 说明                                                                  |
| --------------- | -------- | -- | ------------------------------------------------------------------- |
| `wallet_pubkey` | `string` | 是  | 要注册的 Solana 钱包公钥。                                                   |
| `signature`     | `string` | 是  | 消息的 Ed25519 签名，base58 编码。                                           |
| `message`       | `string` | 是  | 结构化消息：`lasersell-register:<pubkey>:<unix_timestamp>`。时间戳必须在 5 分钟以内。 |
| `label`         | `string` | 否  | 钱包的可选人类可读标签。                                                        |

### 响应

```json theme={null}
{
  "wallet_pubkey": "YourWalletPubkey...",
  "registered": true
}
```

### 认证

需要带有有效 API 密钥的 `x-api-key` 头。

### 错误

| 状态  | 代码          | 说明                             |
| --- | ----------- | ------------------------------ |
| 400 | Bad Request | 无效的公钥格式、格式错误的消息或过期的时间戳（>5 分钟）。 |
| 403 | Forbidden   | 缺少或无效的 API 密钥，或签名验证失败。         |

## `DELETE /v1/wallets`

取消注册钱包。

### 请求

```json theme={null}
{
  "wallet_pubkey": "YourWalletPubkey..."
}
```

### 响应

```json theme={null}
{
  "wallet_pubkey": "YourWalletPubkey...",
  "removed": true
}
```

## SDK 用法

所有 4 种 SDK 都提供钱包注册的辅助方法。

### `proveOwnership` / `prove_ownership`

使用你的密钥对在本地生成 `WalletProof`。这是纯加密操作，无网络调用。

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { proveOwnership } from "@lasersell/lasersell-sdk";

  const proof = proveOwnership(keypair);
  // proof = { walletPubkey, signature, message }
  ```

  ```python Python theme={null}
  from lasersell_sdk.exit_api import prove_ownership

  proof = prove_ownership(keypair)
  # proof = WalletProof(wallet_pubkey, signature, message)
  ```

  ```rust Rust theme={null}
  use lasersell_sdk::exit_api::prove_ownership;

  let proof = prove_ownership(&keypair);
  // proof = WalletProof { wallet_pubkey, signature, message }
  ```

  ```go Go theme={null}
  proof := lasersell.ProveOwnership(privateKey)
  // proof = WalletProof{WalletPubkey, Signature, Message}
  ```
</CodeGroup>

### `registerWallet` / `register_wallet`

将证明发送到 API 以注册钱包。

<CodeGroup>
  ```typescript TypeScript theme={null}
  const client = ExitApiClient.withApiKey(apiKey);
  await client.registerWallet(proof, "My Wallet");
  ```

  ```python Python theme={null}
  client = ExitApiClient.with_api_key(api_key)
  await client.register_wallet(proof, label="My Wallet")
  ```

  ```rust Rust theme={null}
  client.register_wallet(&proof, Some("My Wallet")).await?;
  ```

  ```go Go theme={null}
  client.RegisterWallet(ctx, proof, lasersell.Ptr("My Wallet"))
  ```
</CodeGroup>

### `connectWithWallets` / `connect_with_wallets`

便捷方法，一步完成注册钱包和连接流。

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { StreamClient, proveOwnership } from "@lasersell/lasersell-sdk";

  const proof = proveOwnership(keypair);
  const client = new StreamClient(apiKey);
  const session = await client.connectWithWallets(
    [proof],
    { target_profit_pct: 50, stop_loss_pct: 10 },
    120, // deadline_timeout_sec
  );
  ```

  ```python Python theme={null}
  from lasersell_sdk.exit_api import prove_ownership
  from lasersell_sdk.stream.client import StreamClient

  proof = prove_ownership(keypair)
  client = StreamClient(api_key)
  session = await client.connect_with_wallets(
      [proof],
      {"target_profit_pct": 50, "stop_loss_pct": 10},
      deadline_timeout_sec=120,
  )
  ```

  ```rust Rust theme={null}
  let proof = prove_ownership(&keypair);
  let client = StreamClient::new(api_key);
  let session = client.connect_with_wallets(
      &[proof],
      strategy,
      120,
  ).await?;
  ```

  ```go Go theme={null}
  // Go SDK: register separately, then connect
  proof := lasersell.ProveOwnership(privateKey)
  client.RegisterWallet(ctx, proof, nil)
  session, _ := stream.ConnectSession(ctx, streamClient, configure)
  ```
</CodeGroup>
