# @bitgo/bip174 中文文档

规范地址：https://npmcn.com/package/%40bitgo/bip174/

版本：3\.0\.0-rc\.1
npm 元数据更新时间：2026-03-09T04:23:33.936Z
中文译文更新时间：2026-11-08T05:02:15.900Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40bitgo/bip174
原文对照：https://npmcn.com/package/%40bitgo/bip174/?lang=original
项目主页：https://github.com/BitGo/bip174#readme
源码仓库：https://github.com/BitGo/bip174

弃用说明：deprecate

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

- 包体积（解压后）：95.7 kB，65 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=8\.0\.0
- 运行依赖：0 个
- 首次发布：2022-08-31T21:23:16.231Z
- 最新版本发布：2023-01-23T16:35:38.543Z
- 近 30 天下载量：2422（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：2（近 12 个月 0 个）

## 中文简介

BitGo 特定修改的bip174叉

## 安装

```sh
npm install @bitgo/bip174
```

也可以使用：`pnpm add @bitgo/bip174`、`yarn add @bitgo/bip174`、`bun add @bitgo/bip174`

## README

# 第174页

[![Build Status](https://travis-ci.org/bitcoinjs/bip174.png?branch=master)](https://travis-ci.org/bitcoinjs/bip174) [![NPM](https://img.shields.io/npm/v/bip174.svg)](https://www.npmjs.org/package/bip174)

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)

A 类 [BIP174 投资促进局](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) 兼容部分交易编码库.

## 比特币用户,使用比特币js-lib的Psbt类.

这个库是分开的,试图将比特币特定逻辑与编码格式区分开来.

如果图书馆很难使用,我道歉。 从“ 部分签名的 BITCOIN 交易” 格式中删除比特币特定逻辑有点困难 .

## 涵盖的责任

1.  创建者:您可以创建一个新的 psbt 并添加输入和输出,然后使用每个单个方法在输入中添加额外信息. (注: Psbt. from Transaction 可以从序列化交易中创建一个PSBT,但所有的脚本Sigs和目击Stacks必须是空的, 交易中不应有鼠标和旗字节。)
2.  更新器:您可以添加所有类型的输入和输出信息之一. 每个功能在运行时都有严格的类型检查.
3.  组合器:使用 Psbt.combine(. Psbt\[\]),它会做一个愚蠢的合并,从后续的PSBT中将所有新的密钥值对集合到自己中去. 电话打来 `combine` 拥有最高优先权.

## 未涵盖的责任

为了尽可能地将这个图书馆与比特币逻辑区分开来,这个图书馆不会执行以下职责. 但是,在这条路上,比特币(Bitcoinjs-lib)将采用这一类,并在内部扩展,以允许以下内容:

1.  签名人:这门课没有办法签字. 您可以添加部分西格对象 .
2.  提取器 : 这个类对比特币交易知之甚少,所以从一个PSBT创建一个完整的交易必须用比特币意识扩展类来完成.
3.  输入定稿 : 这个类,同样地,对一个输入是否完成一无所知.

## 静态方法和添加输入/ 添加输出需要一个抽象的交易对象

-   静态方法: 必须通过 `TransactionFromBuffer` 键入函数。 见 `ts_src/lib/interfaces.ts` 用于信息 `Transaction` 接口和 `TransactionFromBuffer` 函数.
-   添加输入/输出方法: 构造器需要一个 `Transaction` 抽象界面, 将使用添加输入/ 添加输出方法.

## 示例

```javascript
const { Psbt } = require('bip174')
const { PsbtTransaction , pTxFromBuffer } = require('./someImplementation')
// Psbt requires a Transaction interface to create an instance, as well as
// A function that turns a buffer into that interface. See Transaction and TransactionFromBuffer
// in ts_src/lib/interfaces.ts ...

// See tests/utils/txTools file for an example of a simple Bitcoin Transaction.
// Also see BitcoinJS-lib for an extended class that uses the Transaction class internally.
// Anyone using this library for Bitcoin specifically should use bitcoinjs-lib

// Your PsbtTransaction will have a toBuffer function to allow for serialization
const tx = pTxFromBuffer(someTransactionBuffer);
const psbt = new Psbt(tx)

// OR

// This will parse the PSBT, and use the function you pass to parse the Transaction part
// the function should throw if the scriptSig section is not empty
const psbt = Psbt.fromBuffer(somePsbtBuffer, pTxFromBuffer)

psbt.addInput({
  hash: '865dce988413971fd812d0e81a3395ed916a87ea533e1a16c0f4e15df96fa7d4',
  index: 3,
})
psbt.addInput({
  hash: 'ff5dce988413971fd812d0e81a3395ed916a87ea533e1a16c0f4e15df96fa7d4',
  index: 1,
})
psbt.addOutput({
  script: Buffer.from(
    'a914e18870f2c297fbfca54c5c6f645c7745a5b66eda87',
    'hex',
  ),
  value: 1234567890,
})
psbt.addOutput({
  script: Buffer.from(
    'a914e18870f2c297fbfca54c5c6f645c7745a5b66eda87',
    'hex',
  ),
  value: 987654321,
})
psbt.addRedeemScriptToInput(0, Buffer.from(
  '00208c2353173743b595dfb4a07b72ba8e42e3797da74e87fe7d9d7497e3b2028903',
  'hex',
))
psbt.addWitnessScriptToInput(0, Buffer.from(
  '522103089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b9903' +
    '0b02dc21023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e861519268' +
    '60221f0e7352ae',
  'hex',
))
psbt.addBip32DerivationToInput(0, {
  masterFingerprint: Buffer.from('d90c6a4f', 'hex'),
  pubkey: Buffer.from(
    '023add904f3d6dcf59ddb906b0dee23529b7ffb9ed50e5e86151926860221f0e73',
    'hex',
  ),
  path: "m/0'/0'/3'",
})
psbt.addBip32DerivationToInput(0, {
  masterFingerprint: Buffer.from('d90c6a4f', 'hex'),
  pubkey: Buffer.from(
    '03089dc10c7ac6db54f91329af617333db388cead0c231f723379d1b99030b02dc',
    'hex',
  ),
  path: "m/0'/0'/2'",
})
const b64 = psbt.toBase64();
```

## 自由主义 [麻省理工学院](https://npmcn.com/package/%40bitgo/bip174/LICENSE)

## 常见问题

### @bitgo/bip174 是什么？

BitGo 特定修改的bip174叉注意：该包已被作者标记为弃用——deprecate

### 如何安装 @bitgo/bip174？

在项目目录运行 npm install @bitgo/bip174，或使用 pnpm add / yarn add / bun add。

### @bitgo/bip174 支持 TypeScript 吗？

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

### @bitgo/bip174 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @bitgo/bip174 需要什么版本的 Node\.js？

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

### @bitgo/bip174 可以商用吗？

@bitgo/bip174 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @bitgo/bip174 的下载量有多少？

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

### @bitgo/bip174 还在维护吗？

最新版本 3\.0\.0-rc\.1 发布于 2023/01/24（3 年前）；至今共发布 2 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/09/01。作者已将其标记为弃用，新项目建议寻找替代方案。

