# @babylonlabs-io/wallet-connector 中文文档

规范地址：https://npmcn.com/package/%40babylonlabs-io/wallet-connector/

版本：5\.2\.11
npm 元数据更新时间：2026-11-05T10:15:14.050Z
中文译文更新时间：2026-11-07T15:40:15.014Z
软件包许可：未声明

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

原始 npm 页面：https://www.npmjs.com/package/%40babylonlabs-io/wallet-connector
原文对照：https://npmcn.com/package/%40babylonlabs-io/wallet-connector/?lang=original
项目主页：https://github.com/babylonlabs-io/babylon-toolkit#readme
源码仓库：https://github.com/babylonlabs-io/babylon-toolkit

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

- 包体积（解压后）：52.1 MB，205 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：6 个
- peer 依赖：viem ^2\.38\.2，react 18\.3\.1，wagmi 2\.18\.1，react-dom 18\.3\.1，bitcoinjs-lib 6\.1\.7，tailwind-merge 2\.5\.4，@keystonehq/sdk 0\.22\.1，@cosmjs/stargate 0\.36\.0，@cosmjs/proto-signing 0\.36\.0，@tanstack/react-query ^5\.74\.4，@reown/appkit-adapter-bitcoin 1\.8\.12，@babylonlabs-io/ledger-vault-signer 3\.1\.11
- 首次发布：2025-02-25T14:52:43.834Z
- 最新版本发布：2026-11-05T10:15:13.689Z
- 近 30 天下载量：7110（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：348（近 12 个月 202 个）

## 中文简介

![Babylon Logo](https://github.com/user-attachments/assets/dc74271e-90f1-44bd-9122-2b7438ab375c)

### @babylonlabs-io/wallet-连接器

## 安装

```sh
npm install @babylonlabs-io/wallet-connector
```

也可以使用：`pnpm add @babylonlabs-io/wallet-connector`、`yarn add @babylonlabs-io/wallet-connector`、`bun add @babylonlabs-io/wallet-connector`

## README

![Babylon Logo](https://github.com/user-attachments/assets/dc74271e-90f1-44bd-9122-2b7438ab375c)

### @babylonlabs-io/wallet-连接器

巴比伦钱包连接器

  

-   [关键特性](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-key-features)
-   [概览](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-overview)
-   [安装](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-installation)
-   [版本发布](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-version-release)
    -   [稳定版本](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-stable-version)
-   [故事书](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-storybook)
-   [钱包整合](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-wallet-integration)
    -   [1\. 浏览器扩展钱包](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-1-browser-extension-wallets)
    -   [2\. 移动钱包](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-2-mobile-wallets)
    -   [IProvider 软件](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-iprovider)
        -   [IBTC 服务器](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-ibtcprovider)
        -   [ISBN 提供](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-ibbnprovider)
        -   [签名 Psbt 选项](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-signpsbtoptions)
        -   [IETH 提供](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-iethprovider)
    -   [钱包注射](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-wallet-injection)
-   [默认整合指南](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/#readme-vault-integration-guide)

巴比伦钱包连接器仓库提供钱包连接组件 用于巴比伦 dApps. 这个组件可以连接比特币,巴比伦 创世纪连锁店 还有伊特鲁姆钱包.

## 关键特性

-   比特币、巴比伦和Ethereum钱包连接的统一接口
-   支持浏览器扩展钱包
-   支持硬件钱包
-   通过可注入接口实现移动钱包兼容性
-   Tomo 为更广泛的钱包生态系统连接集成

## \* 概览

巴比伦钱包连接器提供了整合的统一接口 比特币,巴比伦,和伊特鲁姆钱包入巴比伦dApps. 它支持本土 钱包扩展名,可注入的移动钱包,以及ETH的AppKit/WalletConnect.

主要的建筑区别在于 原生钱包被安装在 库,而可注入的钱包可以通过插入其 落实到网页 `window` dApp 装入前的对象.

## \* 安装

```bash
npm i @babylonlabs-io/wallet-connector
```

## QQ 提交格式和自动发布

这个项目使用 [**常规武器委员会**](https://www.conventionalcommits.org/en/v1.0.0/) 财务报告和审定财务报表 [**语义释放**](https://semantic-release.gitbook.io/) 自动化 版本化,更动日志生成,和npm出版.

### \* 如何运作

1.  所有承诺都必须遵循 **常规武器委员会** 格式.
2.  当更改合并为 `main` 分支 :
    -   `semantic-release` 分析消息
    -   确定适当的语义版本凸起( E)`major`, (中文(简体) ), `minor`, (中文(简体) ), `patch`(中文(简体) )
    -   用 Git 标记发布时的更改日志
    -   将新版本发布到 npm

### QQ 提交信件示例

```console
feat: add support for slashing script
fix: handle invalid staking tx gracefully
docs: update README with commit conventions
refactor!: remove deprecated method and cleanup types
```

> **说明:** 对于断开更改,添加一个 `!` 在类型之后(例如:. `feat!:` 或者说 `refactor!:`(a) 并包括说明所犯罪行的突破性变化 躯体.

### · 释出

只需使用适当的格式将您的更改输入并合并到 `main`. 犯罪调查 管道将自动处理版本和释放——不手工标记 或需要版本的凸起.

## · 故事本

```bash
npm run dev
```

## 钱包整合

> ⚠️ **重要性**: 打破巴比伦人使用的钱包方法的修改 网络应用程序可能造成与其不相容或导致 有严重后果的出乎意料的行为.
> 
> 请确保始终保持后向兼容和测试 所有影响巴比伦网络所需方法的变化 应用。 如果你不确定有什么变化 请联系巴比伦 实验室团队.

本指南解释了如何将钱包与巴比伦dApps整合. 这个 钱包连接器通过两个集成路径支持比特币,巴比伦和埃特鲁姆钱包:

### 1\. 浏览器扩展钱包

建议的将钱包与巴比伦dApps整合的方法是: [Tomo 连接 SDK 字节](https://docs.tomo.inc/tomo-sdk/tomo-connect-sdk-lite)。 。 。 . 有关整合详情,请参见托莫的文档.

### 2\. 移动钱包

完整的界面定义可见于 [弧度/分数/类型](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/src/core/types.ts)。 。 。 .

下面我们概述了比特币、巴比伦和伊特鲁姆钱包的接口,这些钱包需要 与巴比伦dApps合并.

### IProvider 软件

```ts
export interface IProvider {
  /**
   * Connects to the wallet and returns the instance of the wallet provider.
   * Currently Bitcoin only supports Native SegWit and Taproot address types.
   * @returns A promise that resolves to an instance of the wrapper wallet provider.
   * @throws An error if the wallet is not installed or if connection fails.
   */
  connectWallet(): Promise<void>;

  /**
   * Gets the address of the connected wallet.
   * @returns A promise that resolves to the address of the connected wallet.
   */
  getAddress(): Promise<string>;

  /**
   * Gets the public key of the connected wallet.
   * @returns A promise that resolves to the public key of the connected wallet.
   */
  getPublicKeyHex(): Promise<string>;
}
```

#### IBTC 服务器

```ts
interface IBTCProvider extends IProvider {
  /**
   * Signs the given PSBT in hex format.
   * @param psbtHex - The hex string of the unsigned PSBT to sign.
   * @param options - Optional parameters for signing the PSBT.
   * @returns A promise that resolves to the hex string of the signed PSBT.
   */
  signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;

  /**
   * Signs multiple PSBTs in hex format.
   * @param psbtsHexes - The hex strings of the unsigned PSBTs to sign.
   * @param options - Optional parameters for signing the PSBTs.
   * @returns A promise that resolves to an array of hex strings, each representing a signed PSBT.
   */
  signPsbts(
    psbtsHexes: string[],
    options?: SignPsbtOptions[],
  ): Promise<string[]>;

  /**
   * Gets the network of the current account.
   * @returns A promise that resolves to the network of the current account.
   */
  getNetwork(): Promise<Network>;

  /**
   * Signs a message using either BIP322-Simple or ECDSA signing method.
   * @param message - The message to sign.
   * @param type - The signing method to use.
   * @returns A promise that resolves to the signed message.
   */
  signMessage(
    message: string,
    type: "bip322-simple" | "ecdsa",
  ): Promise<string>;

  /**
   * Lists the wallet's inscribed outpoints, read from the wallet's own
   * inscription index, so callers can keep those UTXOs out of funding.
   *
   * Resolve only from a real index. An empty array means "checked, none
   * inscribed", and `fetchOrdinals` then skips the ordinals API, which it uses
   * only when this call rejects, times out or resolves a non-array. A wallet
   * without an inscription index must reject, never resolve `[]`.
   * @returns A promise that resolves to the inscribed outpoints.
   */
  getInscriptions(): Promise<InscriptionIdentifier[]>;

  /**
   * Registers an event listener for the specified event.
   * At the moment, only the "accountChanged" event is supported.
   * @param eventName - The name of the event to listen for.
   * @param callBack - The callback function to be executed when the event occurs.
   */
  on(eventName: string, callBack: () => void): void;

  /**
   * Unregisters an event listener for the specified event.
   * @param eventName - The name of the event to listen for.
   * @param callBack - The callback function to be executed when the event occurs.
   */
  off(eventName: string, callBack: () => void): void;

  /**
   * Gets the name of the wallet provider.
   * @returns A promise that resolves to the name of the wallet provider.
   */
  getWalletProviderName(): Promise<string>;

  /**
   * Gets the icon of the wallet provider.
   * @returns A promise that resolves to the icon of the wallet provider.
   */
  getWalletProviderIcon(): Promise<string>;

  /**
   * Gets the version of the wallet provider.
   * @returns A promise that resolves to the version of the wallet provider.
   */
  getVersion?(): Promise<string>;
}
```

#### ISBN 提供

```ts
export interface IBBNProvider extends IProvider {
  /**
   * Gets the name of the wallet provider.
   * @returns A promise that resolves to the name of the wallet provider.
   */
  getWalletProviderName(): Promise<string>;

  /**
   * Gets the icon of the wallet provider.
   * @returns A promise that resolves to the icon of the wallet provider.
   */
  getWalletProviderIcon(): Promise<string>;

  /**
   * Retrieves an offline signer that supports both Amino and Direct signing methods.
   * This signer is used for signing transactions offline before broadcasting them to the network.
   *
   * @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting both Amino and Direct signing
   * @throws {Error} If wallet connection is not established or signer cannot be retrieved
   */
  getOfflineSigner(): Promise<OfflineAminoSigner & OfflineDirectSigner>;

  /**
   * Retrieves an offline signer that supports either Amino or Direct signing methods.
   * This is required for compatibility with older wallets and hardware wallets (like Ledger) that do not support both signing methods.
   * This signer is used for signing transactions offline before broadcasting them to the network.
   *
   * @returns {Promise<OfflineAminoSigner & OfflineDirectSigner>} A promise that resolves to a signer supporting either Amino or Direct signing
   * @throws {Error} If wallet connection is not established or signer cannot be retrieved
   */
  getOfflineSignerAuto?(): Promise<OfflineAminoSigner | OfflineDirectSigner>;

  /**
   * Registers an event listener for the specified event.
   * At the moment, only the "accountChanged" event is supported.
   * @param eventName - The name of the event to listen for.
   * @param callBack - The callback function to be executed when the event occurs.
   */
  on(eventName: string, callBack: () => void): void;

  /**
   * Unregisters an event listener for the specified event.
   * @param eventName - The name of the event to listen for.
   * @param callBack - The callback function to be executed when the event occurs.
   */
  off(eventName: string, callBack: () => void): void;

  /**
   * Gets the version of the wallet provider.
   * @returns A promise that resolves to the version of the wallet provider.
   */
  getVersion?(): Promise<string>;
}
```

#### 签名 Psbt 选项

```ts
export interface SignInputOptions {
  /** Input index to sign */
  index: number;
  /** Address for signing (optional) */
  address?: string;
  /** Public key for signing (optional, hex string) */
  publicKey?: string;
  /** Sighash types (optional) */
  sighashTypes?: number[];
  /**
   * Whether the wallet should sign with the tweaked (key-path) signer.
   * Set `false` for Taproot script-path spends, where signing uses
   * the untweaked internal key. If omitted, the wallet applies its
   * default behavior.
   */
  useTweakedSigner?: boolean;
}

export interface SignPsbtOptions {
  /** Whether to automatically finalize the PSBT after signing */
  autoFinalized?: boolean;
  /**
   * Specific inputs to sign.
   * If not provided, wallet will attempt to sign all inputs it
   * can.
   */
  signInputs?: SignInputOptions[];
}
```

#### IETH 提供

```ts
export interface IETHProvider extends IProvider {
  /**
   * Signs a message using personal_sign (EIP-191).
   */
  signMessage(message: string): Promise<string>;

  /**
   * Signs structured data using eth_signTypedData_v4 (EIP-712).
   */
  signTypedData(typedData: ETHTypedData): Promise<string>;

  /**
   * Sends a transaction to the blockchain.
   * @returns Transaction hash
   */
  sendTransaction(
    tx: ETHTransactionRequest,
  ): Promise<string>;

  /**
   * Estimates gas for a transaction.
   */
  estimateGas(
    tx: ETHTransactionRequest,
  ): Promise<bigint>;

  /**
   * Gets the current chain ID.
   */
  getChainId(): Promise<number>;

  /**
   * Switches to a different chain.
   */
  switchChain(chainId: number): Promise<void>;

  /**
   * Gets the account balance in wei.
   */
  getBalance(): Promise<bigint>;

  /**
   * Gets the account nonce.
   */
  getNonce(): Promise<number>;

  /**
   * Gets network information.
   */
  getNetworkInfo(): Promise<NetworkInfo>;

  /**
   * Gets the wallet provider name (synchronous).
   */
  getWalletProviderName(): string;

  /**
   * Gets the wallet provider icon (synchronous).
   */
  getWalletProviderIcon(): string;

  on(eventName: string, handler: Function): void;
  off(eventName: string, handler: Function): void;
}

export interface ETHTransactionRequest {
  to: string;
  value?: string;
  data?: string;
  gasLimit?: bigint;
  maxFeePerGas?: bigint;
  maxPriorityFeePerGas?: bigint;
  nonce?: number;
}

export interface ETHTypedData {
  domain: {
    name?: string;
    version?: string;
    chainId?: number;
    verifyingContract?: string;
    salt?: string;
  };
  types: Record<
    string,
    Array<{ name: string; type: string }>
  >;
  primaryType: string;
  message: Record<string, any>;
}

export interface NetworkInfo {
  name: string;
  chainId: string;
}
```

> **说明**数字 : `getWalletProviderName()` 财务报告和审定财务报表 `getWalletProviderIcon()` 打开 `IETHProvider` 为: **同步** (返回数) `string`),不同于在 `IBTCProvider` 财务报告和审定财务报表 `IBBNProvider`。 。 。 .

ETH 钱包通过 AppKit / 钱包连接( 标准) EIP-1193 (英语). 没有 `window.ethwallet` 支持注射.

### 钱包注射

1.  执行提供者接口
2.  输入 `window` 装入 dApp 之前 :

```ts
// For Bitcoin wallets
window.btcwallet = new BTCWalletImplementation();

// For Babylon wallets
window.bbnwallet = new BBNWalletImplementation();

// For Ethereum wallets — no injection needed.
// ETH connects via AppKit / WalletConnect.
```

## 默认整合指南

关于将钱包与巴比伦的"无信取出比特币"(TBV)整合的详细文件,包括完整的存款交易流量,签名选项和参考执行,参见: [默认整合指南](https://npmcn.com/package/%40babylonlabs-io/wallet-connector/docs/vault-integration-guide.md)。 。 。 .

## 常见问题

### @babylonlabs-io/wallet-connector 是什么？

@babylonlabs-io/wallet-连接器

### 如何安装 @babylonlabs-io/wallet-connector？

在项目目录运行 npm install @babylonlabs-io/wallet-connector，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：viem（^2\.38\.2）、react（18\.3\.1）、wagmi（2\.18\.1）、react-dom（18\.3\.1）、tailwind-merge（2\.5\.4）、@tanstack/react-query（^5\.74\.4）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @babylonlabs-io/wallet-connector 支持 TypeScript 吗？

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

### @babylonlabs-io/wallet-connector 支持 ESM 还是 CommonJS？

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

### @babylonlabs-io/wallet-connector 可以商用吗？

@babylonlabs-io/wallet-connector 使用 未声明 许可。package\.json 没有声明许可证。没有许可证的代码默认保留全部权利，商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括，不构成法律意见，请以许可原文为准。

### @babylonlabs-io/wallet-connector 的下载量有多少？

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

### @babylonlabs-io/wallet-connector 还在维护吗？

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

