bitcoinjs-lib

在纯 javascript 中实现的与比特币相关的函数。(Bitcoin-related functions implemented in pure JavaScript.)

Github stars Tracking Chart

BitcoinJS(bitcoinjs-lib)

用于node.js和浏览器的纯JavaScript比特币库。 估计有超过1500万个钱包用户在使用,并且是当今生产的几乎所有比特币网络钱包的支柱。

特性

  • 清洁:纯粹的JavaScript,简洁的代码,易于阅读。
  • 测试:覆盖率> 95%的第三方集成测试。
  • 小心:针对小型重点拉式请求的两人审批流程
  • 兼容:适用于Node.js和所有现代浏览器。
  • 强大:支持高级功能,例如multi-sig,HD Wallets。
  • 安全:强大的随机数生成,PGP签名版本,值得信赖的开发人员。
  • Principled:不支持带crap RNG的浏览器(IE<11)
  • 标准化:Node社区编码风格,Browserify,Node的stdlib和缓冲区。
  • 快速:优化代码,使用类型化数组而不是字节数组来提升性能。
  • 实验友好:比特币主网和Testnet支持。
  • Altcoin就绪:可以使用比特币衍生的加密货币(例如Dogecoin)。

我应该在生产中使用它吗?

如果您正在考虑在生产中使用此库的主分支,请停止。 master不稳定,它是我们的开发分支,而 只有标记的版本可能被归类为稳定版本

安装

npm install bitcoinjs-lib

通常我们支持Node Maintenance LTS 版本。 如有疑问,请参阅.travis.yml,了解我们的持续集成测试使用的版本。

警告:我们目前不提供任何工具来验证npm上的发布是否与GitHub匹配。 因此,您应该验证npm下载的任何内容与您自己的经过验证的副本。

示例

下面的例子是作为集成测试来实现的,它们应该很容易理解。 否则,拉请求赞赏。 一些示例与第三方区块链提供商(3PBP)进行交互(通过HTTPS)。

如果您有一个用户可以在此列出,请请问它

使用BitcoinJS的项目

贡献

我们总是接受pull请求,但是我们确实遵守关于编码风格,测试驱动开发和提交消息的特定标准。

请尽力遵守这些规定,以节省琐碎的更正。

运行测试套件

npm test
npm run-script coverage

补充库

  • BIP21 - 兼容BIP21的URL编码库
  • BIP38 - 密码保护私钥
  • BIP39 - 确定性密钥的助记符生成方式
  • BIP32-Utils - 一组用于使用BIP32的实用程序
  • BIP66 - 严格的DER签名解码
  • BIP68 - 相对锁定时间编码库
  • BIP69 - 交易输入和输出的字典索引
  • Base58 - Base58编码/解码
  • Base58检查 - Base58检查编码/解码
  • Bech32 - 符合BIP173的Bech32编码库
  • 共同清点 - 一个针对bitcoinjs-lib的费用优化交易输入选择模块。
  • merkle-lib - 用于merkle根和树计算的性能敏感库。
  • minimaldata - 检查比特币政策的模块:SCRIPT_VERIFY_MINIMALDATA

替代

LICENSE MIT

Overview

Name With Ownerbitcoinjs/bitcoinjs-lib
Primary LanguageTypeScript
Program languageJavaScript (Language Count: 2)
PlatformCross-platform, Linux, Mac, Web browsers, Windows
License:MIT License
Release Count86
Last Release Namev6.1.5 (Posted on 2023-09-18 16:25:41)
First Release Name0.0.1 (Posted on 2014-02-26 09:00:05)
Created At2011-05-04 16:03:45
Pushed At2024-05-10 04:14:56
Last Commit At2024-05-01 09:43:37
Stargazers Count5.6k
Watchers Count193
Fork Count2k
Commits Count3.1k
Has Issues Enabled
Issues Count1180
Issue Open Count38
Pull Requests Count659
Pull Requests Open Count11
Pull Requests Close Count217
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

BitcoinJS (bitcoinjs-lib)

Build Status
NPM

code style: prettier

A javascript Bitcoin library for node.js and browsers. Written in TypeScript, but committing the JS files to verify.

Released under the terms of the MIT LICENSE.

Should I use this in production?

If you are thinking of using the master branch of this library in production, stop.
Master is not stable; it is our development branch, and only tagged releases may be classified as stable.

Can I trust this code?

Don't trust. Verify.

We recommend every user of this library and the bitcoinjs ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.

Mistakes and bugs happen, but with your help in resolving and reporting issues, together we can produce open source software that is:

  • Easy to audit and verify,
  • Tested, with test coverage >95%,
  • Advanced and feature rich,
  • Standardized, using prettier and Node Buffer's throughout, and
  • Friendly, with a strong and helpful community, ready to answer questions.

Documentation

Presently, we do not have any formal documentation other than our examples, please ask for help if our examples aren't enough to guide you.

Installation

npm install bitcoinjs-lib

Typically we support the Node Maintenance LTS version.
If in doubt, see the .travis.yml for what versions are used by our continuous integration tests.

WARNING: We presently don't provide any tooling to verify that the release on npm matches GitHub. As such, you should verify anything downloaded by npm against your own verified copy.

Usage

Crypto is hard.

When working with private keys, the random number generator is fundamentally one of the most important parts of any software you write.
For random number generation, we default to the randombytes module, which uses window.crypto.getRandomValues in the browser, or Node js' crypto.randomBytes, depending on your build system.
Although this default is ~OK, there is no simple way to detect if the underlying RNG provided is good enough, or if it is catastrophically bad.
You should always verify this yourself to your own standards.

This library uses tiny-secp256k1, which uses RFC6979 to help prevent k re-use and exploitation.
Unfortunately, this isn't a silver bullet.
Often, Javascript itself is working against us by bypassing these counter-measures.

Problems in Buffer (UInt8Array), for example, can trivially result in catastrophic fund loss without any warning.
It can do this through undermining your random number generation, accidentally producing a duplicate k value, sending Bitcoin to a malformed output script, or any of a million different ways.
Running tests in your target environment is important and a recommended step to verify continuously.

Finally, adhere to best practice.
We are not an authorative source of best practice, but, at the very least:

  • Don't re-use addresses.
  • Don't share BIP32 extended public keys ('xpubs'). They are a liability, and it only takes 1 misplaced private key (or a buggy implementation!) and you are vulnerable to catastrophic fund loss.
  • Don't use Math.random - in any way - don't.
  • Enforce that users always verify (manually) a freshly-decoded human-readable version of their intended transaction before broadcast.
  • Don't ask users to generate mnemonics, or 'brain wallets', humans are terrible random number generators.
  • Lastly, if you can, use Typescript or similar.

Browser

The recommended method of using bitcoinjs-lib in your browser is through Browserify.
If you're familiar with how to use browserify, ignore this and carry on, otherwise, it is recommended to read the tutorial at https://browserify.org/.

NOTE: We use Node Maintenance LTS features, if you need strict ES5, use --transform babelify in conjunction with your browserify step (using an es2015 preset).

WARNING: iOS devices have problems, use atleast buffer@5.0.5 or greater, and enforce the test suites (for Buffer, and any other dependency) pass before use.

Typescript or VSCode users

Type declarations for Typescript are included in this library. Normal installation should include all the needed type information.

Examples

The below examples are implemented as integration tests, they should be very easy to understand.
Otherwise, pull requests are appreciated.
Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).

If you have a use case that you feel could be listed here, please ask for it!

Contributing

See CONTRIBUTING.md.

Running the test suite

npm test
npm run-script coverage

Complementing Libraries

  • BIP21 - A BIP21 compatible URL encoding library
  • BIP38 - Passphrase-protected private keys
  • BIP39 - Mnemonic generation for deterministic keys
  • BIP32-Utils - A set of utilities for working with BIP32
  • BIP66 - Strict DER signature decoding
  • BIP68 - Relative lock-time encoding library
  • BIP69 - Lexicographical Indexing of Transaction Inputs and Outputs
  • Base58 - Base58 encoding/decoding
  • Base58 Check - Base58 check encoding/decoding
  • Bech32 - A BIP173 compliant Bech32 encoding library
  • coinselect - A fee-optimizing, transaction input selection module for bitcoinjs-lib.
  • merkle-lib - A performance conscious library for merkle root and tree calculations.
  • minimaldata - A module to check bitcoin policy: SCRIPT_VERIFY_MINIMALDATA

Alternatives

LICENSE MIT

To the top