@exodus/ledger-bitcoin

中文文档
0.3.0-exodus.0发布于 2026/06/25Apache-2.0TypeScriptES Module近 30 天下载 1.6万

Ledger Hardware Wallet Bitcoin Application Client

原始使用文档
文档目录4 节
  1. Overview
  2. Install
  3. Building
  4. Getting started

Ledger Bitcoin application client

Overview

TypeScript client for Ledger Bitcoin application. Supports versions 2.1.0 and above of the app.

Main repository and documentation: https://github.com/LedgerHQ/app-bitcoin-new

Forked at 835245ee9dd93f7f8aa6f2bdf16a7002059cb94d

Install

$ yarn add ledger-bitcoin

Or if you prefer using npm:

$ npm install ledger-bitcoin

Building

$ yarn

$ yarn build

Getting started

The following example showcases all the main methods of the Client's interface.

Testing the signPsbt method requires a valid PSBT, and provide the corresponding wallet policy; it is skipped by default in the following example.

import { AppClient, DefaultWalletPolicy, WalletPolicy } from 'ledger-bitcoin';
import Transport from '@ledgerhq/hw-transport-node-hid';

// This examples assumes the Bitcoin Testnet app is running.
// Make sure to use addresses compatible with mainnet otherwise, by using paths where the BIP-44 coin_type
// is "0'" and not "1'".

async function main(transport) {
    const app = new AppClient(transport);

    // ==> Get the master key fingerprint
    const fpr = await app.getMasterFingerprint();
    console.log("Master key fingerprint:", fpr.toString("hex"));

    // ==> Get and display on screen the first taproot address
    const firstTaprootAccountPubkey = await app.getExtendedPubkey("m/86'/1'/0'");
    const firstTaprootAccountPolicy = new DefaultWalletPolicy(
        "tr(@0/**)",
        `[${fpr}/86'/1'/0']${firstTaprootAccountPubkey}`
    );

    const firstTaprootAccountAddress = await app.getWalletAddress(
        firstTaprootAccountPolicy,
        null,
        0,
        0,
        true // show address on the wallet's screen
    );

    console.log("First taproot account receive address:", firstTaprootAccountAddress);

    // ==> Register a multisig wallet named "Cold storage"

    const ourPubkey = await app.getExtendedPubkey("m/48'/1'/0'/2'");
    const ourKeyInfo = `[${fpr}/48'/1'/0'/2']${ourPubkey}`;
    const otherKeyInfo = "[76223a6e/48'/1'/0'/2']tpubDE7NQymr4AFtewpAsWtnreyq9ghkzQBXpCZjWLFVRAvnbf7vya2eMTvT2fPapNqL8SuVvLQdbUbMfWLVDCZKnsEBqp6UK93QEzL8Ck23AwF";

    const multisigPolicy = new WalletPolicy(
        "Cold storage",
        "wsh(sortedmulti(2,@0/**,@1/**))", // a 2-of-2 multisig policy template
        [
            otherKeyInfo, // some other bitcoiner
            ourKeyInfo,   // that's us
        ]
    )

    const [policyId, policyHmac] = await app.registerWallet(multisigPolicy);

    console.log(`Policy hmac: ${policyHmac.toString("hex")}. Store it safely (together with the policy).`);

    console.assert(policyId.compare(multisigPolicy.getId()) == 0)  //  should never fail

    // ==> Derive and show an address for "Cold storage" that was just registered

    const multisigAddress = await app.getWalletAddress(multisigPolicy, policyHmac, 0, 0, true);
    console.log(`Multisig wallet address: ${multisigAddress}`);

    // ==> Sign a psbt

    // TODO: set a wallet policy and a valid psbt file in order to test psbt signing
    const psbt = null; // a base64-encoded psbt, or a binary psbt in a Buffer
    const signingPolicy = null; // an instance of WalletPolicy
    const signingPolicyHmac = null; // if not a default wallet policy, this must also be set
    if (!psbt || !signingPolicy) {
        console.log("Nothing to sign :(");
        await transport.close();
        return;
    }

    // result will be a list of triples [i, partialSig], where:
    // - i is the input index
    // - partialSig is an instance of PartialSignature; it contains a pubkey and a signature,
    //   and it might contain a tapleaf_hash.
    const result = await app.signPsbt(psbt, signingPolicy, signingPolicyHmac);

    console.log("Returned signatures:");
    console.log(result);

    await transport.close();
}

Transport.default.create()
    .then(main)
    .catch(console.log);

版本与发布记录

@exodus/ledger-bitcoin 共发布 11 个版本,首次发布于 2023/12/06;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.3.0-exodus.0latest2026/06/254 个月前
0.2.3-exodus.9exodus2026/04/166 个月前
0.2.3-exodus.82025/01/091.8 年前
0.2.3-exodus.72025/01/091.8 年前
0.2.3-exodus.62024/11/282 年前
0.2.3-exodus.52024/03/042 年前

关于 @exodus/ledger-bitcoin 的常见问题

@exodus/ledger-bitcoin 是什么?

Ledger Hardware Wallet Bitcoin Application Client

如何安装 @exodus/ledger-bitcoin?

在项目目录运行 npm install @exodus/ledger-bitcoin,或使用 pnpm add / yarn add / bun add。

@exodus/ledger-bitcoin 支持 TypeScript 吗?

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

@exodus/ledger-bitcoin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@exodus/ledger-bitcoin 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@exodus/ledger-bitcoin 可以商用吗?

@exodus/ledger-bitcoin 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/ledger-bitcoin 的下载量有多少?

根据 npm 官方下载统计,@exodus/ledger-bitcoin 在 2026/10/14 – 2026/11/12 这 30 天内被下载 15,730 次,日均约 524 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/ledger-bitcoin 还在维护吗?

最新版本 0.3.0-exodus.0 发布于 2026/06/25(4 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 2 个;首次发布于 2023/12/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。