# @aptos-labs/derived-wallet-solana 中文文档

规范地址：https://npmcn.com/package/%40aptos-labs/derived-wallet-solana/

版本：0\.12\.2
npm 元数据更新时间：2026-03-09T16:36:52.191Z
中文译文更新时间：2026-11-06T13:08:06.596Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40aptos-labs/derived-wallet-solana
原文对照：https://npmcn.com/package/%40aptos-labs/derived-wallet-solana/?lang=original
项目主页：https://github.com/aptos-labs/aptos-wallet-adapter#readme
源码仓库：https://github.com/aptos-labs/aptos-wallet-adapter

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：199 kB，37 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：8 个
- peer 依赖：@aptos-labs/ts-sdk ^5\.1\.1
- 首次发布：2025-03-20T23:02:54.594Z
- 最新版本发布：2026-03-09T16:36:51.897Z
- 近 30 天下载量：10566（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 14 个）

## 中文简介

轻量级加载包 [@aptos-labs/wallet-adapter-反应](https://npmcn.com/package/%40aptos-labs/wallet-adapter-react/) 使功能能够使用 Solana 钱包作为原生 Aptos 钱包

## 安装

```sh
npm install @aptos-labs/derived-wallet-solana
```

也可以使用：`pnpm add @aptos-labs/derived-wallet-solana`、`yarn add @aptos-labs/derived-wallet-solana`、`bun add @aptos-labs/derived-wallet-solana`

## README

# 衍生钱包索拉纳

轻量级加载包 [@aptos-labs/wallet-adapter-反应](https://npmcn.com/package/%40aptos-labs/wallet-adapter-react/) 使功能能够使用 Solana 钱包作为原生 Aptos 钱包

### 索拉纳钱包如何使用钱包适配器??

当用户使用所支持的索拉纳钱包连接到dApp时,适配器会计算用户的可衍生摘要账户(DAA)地址并转换索拉纳账户,以遵循Aptos钱包标准接口. 这确保了开发者和终端用户与钱包的无缝互动.

DAA 地址的计算使用 `authenticationFunction` 编辑 `accountIdentity`,两者在本包中定义:

-   `authenticationFunction`:这是一个存在于链上并用于验证EVM账户签名的函数. 该函数存在于 `0x1::solana_derivable_account::authenticate`
-   `accountIdentity`:这是用于验证EVM账户签名的链上认证功能中使用的账户的身份. EVM DAA账户身份格式为: `${originWalletPublicKey}${domain}`

### 如何把索拉纳的钱包纳入我的DApp?

钱包适配器跟随 [索拉纳钱包标准](https://github.com/wallet-standard/wallet-standard/blob/master/DESIGN.md) 以发现钱包. 目前,已测试和支持跨链账户的钱包有:

|  | 阿普托斯·德文内 | Aptos 测试网 | 阿普托斯主网 |
| --- | --- | --- | --- |
| 幽灵 | ✅ | ✅ | ✅ |
| 索夫莱尔 | ✅ | ✅ | ✅ |
| 后包装 | ✅ | ✅ | ✅ |
| OKX 单曲 | ✅ | ✅ | ✅ |

## 使用量

> **说明:** 编程器硬件钱包目前不支持索拉纳衍生出Aptos账户所需的脱链信件签名. 这是莱德格索拉纳应用的已知限制. 用户应当使用软件钱包(Phantom,Solflare等)而无需硬件设备连接.

### 备选案文1:自动钱包检测(建议用于dApps)

在用户连接其索拉纳钱包的 dApp 构建时使用此方法 .

1.  安装软件包

```bash
npm install @aptos-labs/wallet-adapter-react @aptos-labs/derived-wallet-solana
```

2.  设置自动检测

```tsx
import { AptosWalletAdapterProvider, Network } from "@aptos-labs/wallet-adapter-react";
import { setupAutomaticSolanaWalletDerivation } from "@aptos-labs/derived-wallet-solana";

setupAutomaticSolanaWalletDerivation({ defaultNetwork: Network.TESTNET });

// ...

<AptosWalletAdapterProvider
  dappConfig={{
    network: Network.TESTNET,
  }}
>
  {children}
</AptosWalletAdapterProvider>
```

### 备选方案2:程序签名(用于节点/脚本)

在服务器侧签名或脚本中使用此方法, 您可以直接访问 Solana keypair .

```bash
npm install @aptos-labs/derived-wallet-solana
```

```typescript
import { Keypair } from "@solana/web3.js";
import { SolanaDerivedAccount } from "@aptos-labs/derived-wallet-solana";
import { Aptos, AptosConfig, Network } from "@aptos-labs/ts-sdk";

// Create or load a Solana keypair
const solanaKeypair = Keypair.generate();

// Create the derived account
const account = new SolanaDerivedAccount({
  solanaKeypair,
  domain: "my-dapp.com",
});

// Get the derived Aptos address
console.log("Aptos address:", account.accountAddress.toString());

// Sign and submit a transaction
const aptos = new Aptos(new AptosConfig({ network: Network.TESTNET }));

const transaction = await aptos.transaction.build.simple({
  sender: account.accountAddress,
  data: {
    function: "0x1::aptos_account::transfer",
    functionArguments: [recipientAddress, 100],
  },
}),

const response = await aptos.signAndSubmitTransaction({
  signer: account,
  transaction
});

console.log("Transaction hash:", response.hash);
```

## 提交交易(与收费人)

在大多数情况下,允许用户将索拉纳账户的交易提交到Aptos链,需要使用赞助商交易. 这是因为索拉纳账户可能没有APT支付汽油费用. 因此,DApp应考虑维持一个赞助人账户来赞助交易.

```tsx
import React from "react";
import { useWallet } from "@aptos-labs/wallet-adapter-react";
import {
  Aptos,
  AptosConfig,
  Network,
  Ed25519PrivateKey,
  PrivateKey,
  PrivateKeyVariants,
  Account,
} from "@aptos-labs/ts-sdk";

// Initialize an Aptos client
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);

// Generate a sponsor account or use an existing account
const privateKey = new Ed25519PrivateKey(
  PrivateKey.formatPrivateKey("0x123", PrivateKeyVariants.Ed25519),
);
const sponsor = Account.fromPrivateKey({ privateKey });

const SignAndSubmit = () => {
  const { account, signTransaction } = useWallet();

  const onSignAndSubmitTransaction = async () => {
    if (!account) {
      throw new Error(
        "Account is not connected and unable to sign transaction",
      );
    }

    try {
      // Build the transaction
      const rawTransaction = await aptos.transaction.build.simple({
        data: {
          function: "0x1::aptos_account::transfer",
          functionArguments: [account.address.toString(), 1],
        },
        sender: account.address,
        withFeePayer: true,
      });

      // Send it to the wallet to sign
      const walletSignedTransaction = await signTransaction({
        transactionOrPayload: rawTransaction,
      });

      // Sponsor account signs the transaction to pay for the gas fees
      const sponsorAuthenticator = aptos.transaction.signAsFeePayer({
        signer: sponsor,
        transaction: rawTransaction,
      });

      // Submit the transaction to chain
      const txnSubmitted = await aptosClient(network).transaction.submit.simple(
        {
          transaction: rawTransaction,
          senderAuthenticator: walletSignedTransaction.authenticator,
          feePayerAuthenticator: sponsorAuthenticator,
        },
      );

      // if you want to wait for transaction
      await aptos.waitForTransaction({ transactionHash: txnSubmitted.hash });
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <button onClick={onSignAndSubmitTransaction}>
      Sign and submit transaction
    </button>
  );
};

export default SignAndSubmit;
```

## 考虑因素

-   由于来源钱包最有可能没有与Aptos集成,所以在钱包中无法使用模拟.
-   软件包保留了原产地钱包,因此开发人员应该能够通过:

```tsx
import { useWallet } from "@aptos-labs/wallet-adapter-react";

const { isSolanaDerivedWallet } = useWallet();

if (isSolanaDerivedWallet(wallet)) {
  const publicKey = wallet.solanaWallet.publicKey;
}
```

## 资源

-   X-Chain 账户调整器 Demo App
    -   [现场现场](https://x-chain-accounts.vercel.app/)
    -   [源代码](https://npmcn.com/package/apps/nextjs-x-chain/)
-   [AIP-113 衍生账户摘要](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-113.md)
-   [AIP-121 x-链 DAA 使用 Sign-in-With-Solana 认证](https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-121.md)

## 常见问题

### @aptos-labs/derived-wallet-solana 是什么？

轻量级加载包 @aptos-labs/wallet-adapter-反应 使功能能够使用 Solana 钱包作为原生 Aptos 钱包

### 如何安装 @aptos-labs/derived-wallet-solana？

在项目目录运行 npm install @aptos-labs/derived-wallet-solana，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@aptos-labs/ts-sdk（^5\.1\.1）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @aptos-labs/derived-wallet-solana 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @aptos-labs/derived-wallet-solana 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @aptos-labs/derived-wallet-solana 可以商用吗？

@aptos-labs/derived-wallet-solana 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @aptos-labs/derived-wallet-solana 的下载量有多少？

根据 npm 官方下载统计，@aptos-labs/derived-wallet-solana 在 2026/10/07 – 2026/11/05 这 30 天内被下载 10,566 次，日均约 352 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @aptos-labs/derived-wallet-solana 还在维护吗？

最新版本 0\.12\.2 发布于 2026/03/10（7 个月前）；至今共发布 31 个版本，其中过去 12 个月发布了 14 个；首次发布于 2025/03/21。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

