@bitgo/unspents

中文文档
0.51.11发布于 2026/10/23Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 7.5万

Defines the chain codes used for different unspent types and methods to calculate bitcoin transaction sizes

原始使用文档
文档目录5 节
  1. Installation
  2. Dimensions, Virtual Size Estimation
  3. Examples
  4. Continuous Integration
  5. Codes

@bitgo/unspents

The package provides a Dimensions class with methods to calculate bitcoin transaction sizes

Installation

npm install --save @bitgo/unspents

Dimensions, Virtual Size Estimation

The transaction vSize is critical to calculating the proper transaction fee.

The class unspents.Dimensions provides a class that helps work with the components required to calculate an accurate estimate of a transaction vSize.

Examples

import { Codes, Dimensions } from '@bitgo/unspents';
// using raw attributes
new Dimensions({
  nP2shInputs: 1,
  nP2shP2wshInputs: 1,
  nP2wshInputs: 1,
  outputs: { count: 1, size: 32 },
});

// calculate from unspents that have `chain` property (see Chain Codes)
Dimensions.fromUnspents(unspent[0]);
Dimensions.fromUnspents(unspents);

// Signed inputs work too
Dimensions.fromInput(inputs[0]);
Dimensions.fromInputs(inputs);

// Transaction outputs
Dimensions.fromOutputs(outputs[0]);
Dimensions.fromOutputs(outputs);
Dimensions.fromOutputOnChain(Codes.p2sh.internal);
Dimensions.fromOutputScriptLength(31);

// Combining dimensions and estimating their vSize
Dimensions.fromUnspents({ unspents })
  .plus(Dimensions.fromOutputOnChain(Codes.p2shP2wsh.internal).times(nOutputs))
  .getVSize();

Continuous Integration

@bitgo/unspents uses github actions for continuous integration, which is configured by the .github/workflows/ci.yml file in the project root. All changes to the CI process should be done by modifying the .github/workflows/ci.yml file.

Codes

The exported Codes module is now deprecated.

Please use utxo-lib/src/bitgo/wallet/chains instead.

版本与发布记录

@bitgo/unspents 共发布 184 个版本,首次发布于 2019/03/09;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.51.11latest2026/10/2316 天前
0.51.102026/09/022 个月前
0.51.92026/08/272 个月前
0.51.82026/07/293 个月前
0.51.72026/07/233 个月前
0.51.62026/06/045 个月前

其他发布通道:cr604-hf → 0.8.0-hotfix.0,cr406-hf → 0.8.0-hotfix.1,dev → 0.11.0-dev.0,hotfix → 0.8.5-hotfix.1,rc → 0.9.0-rc.6。

关于 @bitgo/unspents 的常见问题

@bitgo/unspents 是什么?

Defines the chain codes used for different unspent types and methods to calculate bitcoin transaction sizes

如何安装 @bitgo/unspents?

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

@bitgo/unspents 支持 TypeScript 吗?

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

@bitgo/unspents 支持 ESM 还是 CommonJS?

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

@bitgo/unspents 可以商用吗?

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

@bitgo/unspents 的下载量有多少?

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

@bitgo/unspents 还在维护吗?

最新版本 0.51.11 发布于 2026/10/23(16 天前);至今共发布 184 个版本,其中过去 12 个月发布了 19 个;首次发布于 2019/03/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。