@btc-vision/bitcoin 7.0.0-alpha.2 → 7.0.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +455 -155
- package/browser/chunks/WorkerSigningPool.sequential-DHha7j0b.js +113 -0
- package/browser/ecc/context.d.ts +22 -21
- package/browser/ecc/context.d.ts.map +1 -1
- package/browser/ecc/index.d.ts +1 -1
- package/browser/ecc/index.d.ts.map +1 -1
- package/browser/ecc/types.d.ts +10 -123
- package/browser/ecc/types.d.ts.map +1 -1
- package/browser/env.d.ts +13 -0
- package/browser/env.d.ts.map +1 -0
- package/browser/index.d.ts +3 -3
- package/browser/index.d.ts.map +1 -1
- package/browser/index.js +5790 -4295
- package/browser/io/index.d.ts +0 -1
- package/browser/io/index.d.ts.map +1 -1
- package/browser/payments/p2tr.d.ts.map +1 -1
- package/browser/psbt/types.d.ts +2 -68
- package/browser/psbt/types.d.ts.map +1 -1
- package/browser/psbt.d.ts +9 -11
- package/browser/psbt.d.ts.map +1 -1
- package/browser/types.d.ts +1 -1
- package/browser/types.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.d.ts +6 -0
- package/browser/workers/WorkerSigningPool.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.node.d.ts +6 -0
- package/browser/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/browser/workers/WorkerSigningPool.sequential.d.ts +69 -0
- package/browser/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts +64 -0
- package/browser/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/browser/workers/index.d.ts +2 -2
- package/browser/workers/index.d.ts.map +1 -1
- package/browser/workers/index.react-native.d.ts +28 -0
- package/browser/workers/index.react-native.d.ts.map +1 -0
- package/browser/workers/psbt-parallel.d.ts +2 -3
- package/browser/workers/psbt-parallel.d.ts.map +1 -1
- package/browser/workers/types.d.ts +12 -0
- package/browser/workers/types.d.ts.map +1 -1
- package/build/ecc/context.d.ts +22 -21
- package/build/ecc/context.d.ts.map +1 -1
- package/build/ecc/context.js +19 -114
- package/build/ecc/context.js.map +1 -1
- package/build/ecc/index.d.ts +1 -1
- package/build/ecc/index.d.ts.map +1 -1
- package/build/ecc/types.d.ts +7 -126
- package/build/ecc/types.d.ts.map +1 -1
- package/build/ecc/types.js +4 -1
- package/build/ecc/types.js.map +1 -1
- package/build/env.d.ts +13 -0
- package/build/env.d.ts.map +1 -0
- package/build/env.js +198 -0
- package/build/env.js.map +1 -0
- package/build/index.d.ts +4 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/io/index.d.ts +0 -1
- package/build/io/index.d.ts.map +1 -1
- package/build/io/index.js +0 -2
- package/build/io/index.js.map +1 -1
- package/build/payments/p2tr.d.ts.map +1 -1
- package/build/payments/p2tr.js +2 -3
- package/build/payments/p2tr.js.map +1 -1
- package/build/psbt/types.d.ts +2 -68
- package/build/psbt/types.d.ts.map +1 -1
- package/build/psbt.d.ts +9 -11
- package/build/psbt.d.ts.map +1 -1
- package/build/psbt.js +38 -53
- package/build/psbt.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/types.d.ts +1 -1
- package/build/types.d.ts.map +1 -1
- package/build/types.js +2 -16
- package/build/types.js.map +1 -1
- package/build/workers/WorkerSigningPool.d.ts +6 -0
- package/build/workers/WorkerSigningPool.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.js +8 -0
- package/build/workers/WorkerSigningPool.js.map +1 -1
- package/build/workers/WorkerSigningPool.node.d.ts +6 -0
- package/build/workers/WorkerSigningPool.node.d.ts.map +1 -1
- package/build/workers/WorkerSigningPool.node.js +9 -2
- package/build/workers/WorkerSigningPool.node.js.map +1 -1
- package/build/workers/WorkerSigningPool.sequential.d.ts +78 -0
- package/build/workers/WorkerSigningPool.sequential.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.sequential.js +160 -0
- package/build/workers/WorkerSigningPool.sequential.js.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts +79 -0
- package/build/workers/WorkerSigningPool.worklet.d.ts.map +1 -0
- package/build/workers/WorkerSigningPool.worklet.js +388 -0
- package/build/workers/WorkerSigningPool.worklet.js.map +1 -0
- package/build/workers/index.d.ts +2 -2
- package/build/workers/index.d.ts.map +1 -1
- package/build/workers/index.js +9 -0
- package/build/workers/index.js.map +1 -1
- package/build/workers/index.react-native.d.ts +28 -0
- package/build/workers/index.react-native.d.ts.map +1 -0
- package/build/workers/index.react-native.js +67 -0
- package/build/workers/index.react-native.js.map +1 -0
- package/build/workers/psbt-parallel.d.ts +2 -3
- package/build/workers/psbt-parallel.d.ts.map +1 -1
- package/build/workers/psbt-parallel.js +4 -4
- package/build/workers/psbt-parallel.js.map +1 -1
- package/build/workers/types.d.ts +12 -0
- package/build/workers/types.d.ts.map +1 -1
- package/package.json +14 -4
- package/src/ecc/context.ts +26 -147
- package/src/ecc/index.ts +2 -2
- package/src/ecc/types.ts +7 -138
- package/src/env.ts +237 -0
- package/src/index.ts +2 -4
- package/src/io/index.ts +0 -3
- package/src/payments/p2tr.ts +2 -2
- package/src/psbt/types.ts +2 -84
- package/src/psbt.ts +63 -121
- package/src/types.ts +5 -28
- package/src/workers/WorkerSigningPool.node.ts +10 -2
- package/src/workers/WorkerSigningPool.sequential.ts +190 -0
- package/src/workers/WorkerSigningPool.ts +9 -0
- package/src/workers/WorkerSigningPool.worklet.ts +519 -0
- package/src/workers/index.react-native.ts +110 -0
- package/src/workers/index.ts +10 -1
- package/src/workers/psbt-parallel.ts +8 -8
- package/src/workers/types.ts +16 -0
- package/test/env.spec.ts +418 -0
- package/test/workers-pool.spec.ts +43 -0
- package/test/workers-sequential.spec.ts +669 -0
- package/test/workers-worklet.spec.ts +500 -0
- package/browser/io/MemoryPool.d.ts +0 -220
- package/browser/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.d.ts +0 -220
- package/build/io/MemoryPool.d.ts.map +0 -1
- package/build/io/MemoryPool.js +0 -309
- package/build/io/MemoryPool.js.map +0 -1
- package/src/io/MemoryPool.ts +0 -343
package/README.md
CHANGED
|
@@ -1,201 +1,501 @@
|
|
|
1
|
-
#
|
|
2
|
-
[](https://github.com/bitcoinjs/bitcoinjs-lib/actions/workflows/main_ci.yml) [](https://www.npmjs.org/package/bitcoinjs-lib) [](https://github.com/prettier/prettier)
|
|
1
|
+
# @btc-vision/bitcoin
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
[](https://github.com/prettier/prettier)
|
|
7
9
|
|
|
8
|
-
##
|
|
9
|
-
If you are thinking of using the *master* branch of this library in production, **stop**.
|
|
10
|
-
Master is not stable; it is our development branch, and [only tagged releases may be classified as stable](https://github.com/bitcoinjs/bitcoinjs-lib/tags).
|
|
10
|
+
## Overview
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
> Don't trust. Verify.
|
|
12
|
+
A client-side Bitcoin library for Node.js and browsers, written in TypeScript. Provides low-level transaction handling, PSBT (Partially Signed Bitcoin Transactions), address encoding/decoding, payment script creation, and cryptographic operations across multiple networks.
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
This is a modernized fork of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) with significant API changes:
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
- **Branded types** (`Bytes32`, `PrivateKey`, `PublicKey`, `Satoshi`, etc.) for compile-time safety
|
|
17
|
+
- **Modular PSBT architecture** split into composable classes (`PsbtCache`, `PsbtSigner`, `PsbtFinalizer`, `PsbtTransaction`)
|
|
18
|
+
- **Worker-based parallel signing** for both Node.js (`worker_threads`) and browsers (Web Workers)
|
|
19
|
+
- **Native `Uint8Array`** throughout (no Node.js `Buffer` dependency)
|
|
20
|
+
- **`bigint` for satoshi values** instead of `number` to prevent precision loss
|
|
21
|
+
- **Structured error hierarchy** with typed error classes
|
|
22
|
+
- **Granular sub-path exports** for tree-shaking
|
|
23
|
+
- **Multi-chain support** including Bitcoin, Litecoin, Dogecoin, Bitcoin Cash, and Dash
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
- Standardized, using [prettier](https://github.com/prettier/prettier) and Node `Buffer`'s throughout, and
|
|
23
|
-
- Friendly, with a strong and helpful community, ready to answer questions.
|
|
25
|
+
> **Breaking Changes from bitcoinjs-lib**
|
|
26
|
+
>
|
|
27
|
+
> This library has undergone massive API-breaking changes. Transaction values use `bigint` (as `Satoshi`), all byte buffers are `Uint8Array` with branded type wrappers, the ECC library must be explicitly initialized, and key management has been moved to [`@btc-vision/ecpair`](https://github.com/btc-vision/ecpair) and [`@btc-vision/bip32`](https://github.com/btc-vision/bip32).
|
|
24
28
|
|
|
25
|
-
##
|
|
26
|
-
Visit our [documentation](https://bitcoinjs.github.io/bitcoinjs-lib/) to explore the available resources. We're continually enhancing our documentation with additional features for an enriched experience. If you need further guidance beyond what our [examples](#examples) offer, don't hesitate to [ask for help](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new). We're here to assist you.
|
|
29
|
+
## Installation
|
|
27
30
|
|
|
28
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npm install @btc-vision/bitcoin
|
|
33
|
+
# Key management libraries (separate packages)
|
|
34
|
+
npm install @btc-vision/ecpair @btc-vision/bip32
|
|
35
|
+
# ECC backend
|
|
36
|
+
npm install tiny-secp256k1
|
|
37
|
+
```
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
**Most of the time, this is not appropriate. Creating issues and pull requests in the open will help others with similar issues, so please try to use public issues and pull requests for communication.**
|
|
39
|
+
Requires Node.js >= 24.0.0.
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
## Quick Start
|
|
34
42
|
|
|
35
|
-
|
|
43
|
+
### Initialize the ECC Library
|
|
36
44
|
|
|
37
|
-
|
|
45
|
+
The ECC library must be initialized before using Taproot, signing, or any elliptic curve operations.
|
|
46
|
+
Two backends are available:
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
**Noble (recommended for browsers)** -- pure JS, no WASM dependency:
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
```typescript
|
|
51
|
+
import { initEccLib } from '@btc-vision/bitcoin';
|
|
52
|
+
import { createNobleBackend } from '@btc-vision/ecpair';
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
``` bash
|
|
45
|
-
npm install bitcoinjs-lib
|
|
46
|
-
# optionally, install a key derivation library as well
|
|
47
|
-
npm install ecpair bip32
|
|
48
|
-
# ecpair is the ECPair class for single keys
|
|
49
|
-
# bip32 is for generating HD keys
|
|
54
|
+
initEccLib(createNobleBackend());
|
|
50
55
|
```
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
**tiny-secp256k1** -- WASM-based, faster in Node.js:
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
```typescript
|
|
60
|
+
import { initEccLib } from '@btc-vision/bitcoin';
|
|
61
|
+
import { createLegacyBackend } from '@btc-vision/ecpair';
|
|
62
|
+
import * as tinysecp from 'tiny-secp256k1';
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
initEccLib(createLegacyBackend(tinysecp));
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Create a Key Pair
|
|
60
68
|
|
|
69
|
+
```typescript
|
|
70
|
+
import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
|
|
71
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
61
72
|
|
|
62
|
-
|
|
63
|
-
Crypto is hard.
|
|
73
|
+
const backend = createNobleBackend();
|
|
64
74
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
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**.
|
|
68
|
-
You should always verify this yourself to your own standards.
|
|
75
|
+
// Random key pair
|
|
76
|
+
const keyPair = ECPairSigner.makeRandom(backend, networks.bitcoin);
|
|
69
77
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
// From WIF
|
|
79
|
+
const imported = ECPairSigner.fromWIF(
|
|
80
|
+
backend,
|
|
81
|
+
'L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr',
|
|
82
|
+
networks.bitcoin,
|
|
83
|
+
);
|
|
84
|
+
```
|
|
73
85
|
|
|
74
|
-
|
|
75
|
-
It can do this through undermining your random number generation, accidentally producing a [duplicate `k` value](https://www.nilsschneider.net/2013/01/28/recovering-bitcoin-private-keys.html), sending Bitcoin to a malformed output script, or any of a million different ways.
|
|
76
|
-
Running tests in your target environment is important and a recommended step to verify continuously.
|
|
86
|
+
### Generate Addresses
|
|
77
87
|
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
```typescript
|
|
89
|
+
import { payments, networks } from '@btc-vision/bitcoin';
|
|
80
90
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
* [Don't use `Math.random`](https://security.stackexchange.com/questions/181580/why-is-math-random-not-designed-to-be-cryptographically-secure) - in any way - don't.
|
|
84
|
-
* Enforce that users always verify (manually) a freshly-decoded human-readable version of their intended transaction before broadcast.
|
|
85
|
-
* [Don't *ask* users to generate mnemonics](https://en.bitcoin.it/wiki/Brainwallet#cite_note-1), or 'brain wallets', humans are terrible random number generators.
|
|
86
|
-
* Lastly, if you can, use [Typescript](https://www.typescriptlang.org/) or similar.
|
|
91
|
+
// P2PKH (Legacy)
|
|
92
|
+
const { address: legacy } = payments.p2pkh({ pubkey: keyPair.publicKey });
|
|
87
93
|
|
|
94
|
+
// P2WPKH (Native SegWit)
|
|
95
|
+
const { address: segwit } = payments.p2wpkh({ pubkey: keyPair.publicKey });
|
|
88
96
|
|
|
89
|
-
|
|
90
|
-
|
|
97
|
+
// P2TR (Taproot) - requires ECC initialization
|
|
98
|
+
import { toXOnly } from '@btc-vision/bitcoin';
|
|
99
|
+
const { address: taproot } = payments.p2tr({
|
|
100
|
+
internalPubkey: toXOnly(keyPair.publicKey),
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// P2SH-P2WPKH (Wrapped SegWit)
|
|
104
|
+
const { address: wrapped } = payments.p2sh({
|
|
105
|
+
redeem: payments.p2wpkh({ pubkey: keyPair.publicKey }),
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// P2SH Multisig (2-of-3)
|
|
109
|
+
const { address: multisig } = payments.p2sh({
|
|
110
|
+
redeem: payments.p2ms({ m: 2, pubkeys: [pubkey1, pubkey2, pubkey3] }),
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Create and Sign a Transaction (PSBT)
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
import { Psbt, networks } from '@btc-vision/bitcoin';
|
|
118
|
+
import { fromHex } from '@btc-vision/bitcoin';
|
|
119
|
+
import type { Satoshi } from '@btc-vision/bitcoin';
|
|
120
|
+
|
|
121
|
+
const psbt = new Psbt({ network: networks.bitcoin });
|
|
122
|
+
|
|
123
|
+
// Add input
|
|
124
|
+
psbt.addInput({
|
|
125
|
+
hash: '7d067b4a697a09d2c3cff7d4d9506c9955e93bff41bf82d439da7d030382bc3e',
|
|
126
|
+
index: 0,
|
|
127
|
+
nonWitnessUtxo: fromHex('0200000001...'),
|
|
128
|
+
sighashType: 1,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Add output (values are bigint)
|
|
132
|
+
psbt.addOutput({
|
|
133
|
+
address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
|
|
134
|
+
value: 80_000n as Satoshi,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// Sign, finalize, and extract
|
|
138
|
+
psbt.signInput(0, keyPair);
|
|
139
|
+
psbt.finalizeAllInputs();
|
|
140
|
+
const txHex = psbt.extractTransaction().toHex();
|
|
141
|
+
```
|
|
91
142
|
|
|
92
|
-
|
|
143
|
+
### Async Signing
|
|
93
144
|
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
|
|
145
|
+
```typescript
|
|
146
|
+
await psbt.signInputAsync(0, keyPair);
|
|
147
|
+
await psbt.signAllInputsAsync(keyPair);
|
|
97
148
|
```
|
|
98
149
|
|
|
99
|
-
|
|
150
|
+
### Parse a Transaction
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import { Transaction } from '@btc-vision/bitcoin';
|
|
154
|
+
|
|
155
|
+
const tx = Transaction.fromHex('0200000001...');
|
|
156
|
+
console.log(tx.version); // 2
|
|
157
|
+
console.log(tx.ins.length); // number of inputs
|
|
158
|
+
console.log(tx.outs.length); // number of outputs
|
|
159
|
+
console.log(tx.toHex()); // round-trip back to hex
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Decode and Encode Addresses
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { address, networks } from '@btc-vision/bitcoin';
|
|
166
|
+
|
|
167
|
+
// Decode any address to its output script
|
|
168
|
+
const outputScript = address.toOutputScript(
|
|
169
|
+
'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
|
|
170
|
+
networks.bitcoin,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Convert output script back to address
|
|
174
|
+
const addr = address.fromOutputScript(outputScript, networks.bitcoin);
|
|
175
|
+
|
|
176
|
+
// Low-level Base58Check
|
|
177
|
+
const { hash, version } = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
|
|
178
|
+
const encoded = address.toBase58Check(hash, version);
|
|
179
|
+
|
|
180
|
+
// Low-level Bech32
|
|
181
|
+
const decoded = address.fromBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
|
|
182
|
+
const bech32Addr = address.toBech32(decoded.data, decoded.version, 'bc');
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Parallel Signing with Workers
|
|
186
|
+
|
|
187
|
+
For high-throughput signing across many inputs, use the worker pool.
|
|
188
|
+
|
|
189
|
+
#### Sign a PSBT in parallel
|
|
190
|
+
|
|
191
|
+
`signPsbtParallel` analyzes inputs, distributes signing across workers, and applies signatures back to the PSBT:
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import { Psbt, networks } from '@btc-vision/bitcoin';
|
|
195
|
+
import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
|
|
196
|
+
|
|
197
|
+
// Create a platform-appropriate pool (Node.js worker_threads or Web Workers)
|
|
198
|
+
const pool = await createSigningPool({ workerCount: 4 });
|
|
199
|
+
pool.preserveWorkers();
|
|
200
|
+
|
|
201
|
+
// Build your PSBT as usual
|
|
202
|
+
const psbt = new Psbt({ network: networks.bitcoin });
|
|
203
|
+
psbt.addInput({ /* ... */ });
|
|
204
|
+
psbt.addInput({ /* ... */ });
|
|
205
|
+
psbt.addOutput({ /* ... */ });
|
|
206
|
+
|
|
207
|
+
// Sign all signable inputs in parallel — replaces signAllInputs / signAllInputsAsync
|
|
208
|
+
const result = await signPsbtParallel(psbt, keyPair, pool);
|
|
209
|
+
|
|
210
|
+
if (result.success) {
|
|
211
|
+
console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
|
|
212
|
+
psbt.finalizeAllInputs();
|
|
213
|
+
const tx = psbt.extractTransaction();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Shut down when done (or keep the pool alive for future PSBTs)
|
|
217
|
+
await pool.shutdown();
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
You can also pass a config object instead of a pool instance. A temporary pool will be created and
|
|
221
|
+
destroyed automatically:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const result = await signPsbtParallel(psbt, keyPair, { workerCount: 4 });
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
#### Low-level batch signing
|
|
228
|
+
|
|
229
|
+
For manual control over sighash computation and task construction:
|
|
230
|
+
|
|
231
|
+
```typescript
|
|
232
|
+
import { createSigningPool, SignatureType } from '@btc-vision/bitcoin/workers';
|
|
233
|
+
|
|
234
|
+
const pool = await createSigningPool({ workerCount: 4 });
|
|
235
|
+
pool.preserveWorkers();
|
|
236
|
+
|
|
237
|
+
const tasks = [
|
|
238
|
+
{
|
|
239
|
+
taskId: 'input-0',
|
|
240
|
+
inputIndex: 0,
|
|
241
|
+
hash: sighash0,
|
|
242
|
+
signatureType: SignatureType.ECDSA,
|
|
243
|
+
sighashType: 0x01,
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
taskId: 'input-1',
|
|
247
|
+
inputIndex: 1,
|
|
248
|
+
hash: sighash1,
|
|
249
|
+
signatureType: SignatureType.Schnorr,
|
|
250
|
+
sighashType: 0x00,
|
|
251
|
+
},
|
|
252
|
+
];
|
|
253
|
+
|
|
254
|
+
const result = await pool.signBatch(tasks, keyPair);
|
|
255
|
+
if (result.success) {
|
|
256
|
+
console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
await pool.shutdown();
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## API Reference
|
|
263
|
+
|
|
264
|
+
### Exports
|
|
265
|
+
|
|
266
|
+
The library provides granular sub-path exports for tree-shaking:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
import { ... } from '@btc-vision/bitcoin'; // Full API
|
|
270
|
+
import { ... } from '@btc-vision/bitcoin/address'; // Address encoding/decoding
|
|
271
|
+
import { ... } from '@btc-vision/bitcoin/script'; // Script compile/decompile
|
|
272
|
+
import { ... } from '@btc-vision/bitcoin/crypto'; // Hash functions
|
|
273
|
+
import { ... } from '@btc-vision/bitcoin/transaction';// Transaction class
|
|
274
|
+
import { ... } from '@btc-vision/bitcoin/psbt'; // PSBT classes
|
|
275
|
+
import { ... } from '@btc-vision/bitcoin/networks'; // Network definitions
|
|
276
|
+
import { ... } from '@btc-vision/bitcoin/payments'; // Payment creators
|
|
277
|
+
import { ... } from '@btc-vision/bitcoin/io'; // Binary I/O utilities
|
|
278
|
+
import { ... } from '@btc-vision/bitcoin/ecc'; // ECC context
|
|
279
|
+
import { ... } from '@btc-vision/bitcoin/types'; // Type definitions & guards
|
|
280
|
+
import { ... } from '@btc-vision/bitcoin/errors'; // Error classes
|
|
281
|
+
import { ... } from '@btc-vision/bitcoin/workers'; // Parallel signing
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Branded Types
|
|
285
|
+
|
|
286
|
+
Values use branded types to prevent accidental misuse:
|
|
287
|
+
|
|
288
|
+
```typescript
|
|
289
|
+
import type {
|
|
290
|
+
Bytes32, // 32-byte Uint8Array (tx hashes, witness programs)
|
|
291
|
+
Bytes20, // 20-byte Uint8Array (pubkey hashes)
|
|
292
|
+
PublicKey, // Compressed/uncompressed public key
|
|
293
|
+
XOnlyPublicKey, // 32-byte x-only pubkey (Taproot)
|
|
294
|
+
PrivateKey, // 32-byte private key
|
|
295
|
+
Satoshi, // bigint value (0 to 21e14)
|
|
296
|
+
Signature, // DER-encoded ECDSA signature
|
|
297
|
+
SchnorrSignature, // 64-byte Schnorr signature
|
|
298
|
+
Script, // Compiled script bytes
|
|
299
|
+
} from '@btc-vision/bitcoin';
|
|
300
|
+
|
|
301
|
+
// Type guards
|
|
302
|
+
import {
|
|
303
|
+
isBytes32, isBytes20, isPoint, isSatoshi,
|
|
304
|
+
isPrivateKey, isSignature, isSchnorrSignature,
|
|
305
|
+
isXOnlyPublicKey, isScript,
|
|
306
|
+
} from '@btc-vision/bitcoin';
|
|
307
|
+
|
|
308
|
+
// Conversion helpers (throw on invalid input)
|
|
309
|
+
import { toBytes32, toBytes20, toSatoshi } from '@btc-vision/bitcoin';
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
### Payment Types
|
|
313
|
+
|
|
314
|
+
| Type | Function | Class | Description |
|
|
315
|
+
|------|----------|-------|-------------|
|
|
316
|
+
| P2PK | `p2pk()` | `P2PK` | Pay-to-Public-Key |
|
|
317
|
+
| P2PKH | `p2pkh()` | `P2PKH` | Pay-to-Public-Key-Hash (Legacy) |
|
|
318
|
+
| P2SH | `p2sh()` | `P2SH` | Pay-to-Script-Hash |
|
|
319
|
+
| P2MS | `p2ms()` | `P2MS` | Pay-to-Multisig |
|
|
320
|
+
| P2WPKH | `p2wpkh()` | `P2WPKH` | SegWit v0 Public Key Hash |
|
|
321
|
+
| P2WSH | `p2wsh()` | `P2WSH` | SegWit v0 Script Hash |
|
|
322
|
+
| P2TR | `p2tr()` | `P2TR` | Taproot (SegWit v1) |
|
|
323
|
+
| P2OP | `p2op()` | `P2OP` | OPNet (SegWit v16) |
|
|
324
|
+
| Embed | `p2data()` | `Embed` | OP_RETURN data |
|
|
325
|
+
|
|
326
|
+
### Network Support
|
|
327
|
+
|
|
328
|
+
| Network | Constant | Bech32 Prefix |
|
|
329
|
+
|---------|----------|---------------|
|
|
330
|
+
| Bitcoin Mainnet | `networks.bitcoin` | `bc` |
|
|
331
|
+
| Bitcoin Testnet | `networks.testnet` | `tb` |
|
|
332
|
+
| Bitcoin Regtest | `networks.regtest` | `bcrt` |
|
|
333
|
+
| Dogecoin | `networks.dogecoin` | - |
|
|
334
|
+
| Litecoin | `networks.litecoin` | `ltc` |
|
|
335
|
+
| Bitcoin Cash | `networks.bitcoinCash` | `bitcoincash` |
|
|
336
|
+
| Dash | `networks.dash` | - |
|
|
337
|
+
|
|
338
|
+
### Error Handling
|
|
339
|
+
|
|
340
|
+
All errors extend `BitcoinError`:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import {
|
|
344
|
+
BitcoinError, // Base class
|
|
345
|
+
ValidationError, // Input validation failures
|
|
346
|
+
InvalidInputError, // Invalid transaction input
|
|
347
|
+
InvalidOutputError,// Invalid transaction output
|
|
348
|
+
ScriptError, // Script operation failures
|
|
349
|
+
PsbtError, // PSBT operation failures
|
|
350
|
+
EccError, // ECC library not initialized
|
|
351
|
+
AddressError, // Address encoding/decoding failures
|
|
352
|
+
SignatureError, // Signature operation failures
|
|
353
|
+
} from '@btc-vision/bitcoin';
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
psbt.signInput(0, signer);
|
|
357
|
+
} catch (err) {
|
|
358
|
+
if (err instanceof PsbtError) {
|
|
359
|
+
// Handle PSBT-specific error
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Utility Functions
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
import {
|
|
368
|
+
toHex, fromHex, isHex, // Hex encoding
|
|
369
|
+
concat, equals, compare, // Buffer operations
|
|
370
|
+
clone, reverse, reverseCopy, // Buffer manipulation
|
|
371
|
+
alloc, xor, isZero, // Buffer utilities
|
|
372
|
+
fromUtf8, toUtf8, // UTF-8 conversion
|
|
373
|
+
toXOnly, // Compress pubkey to x-only (32 bytes)
|
|
374
|
+
decompressPublicKey, // Decompress compressed pubkey
|
|
375
|
+
} from '@btc-vision/bitcoin';
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Crypto Functions
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
import { sha256, sha1, ripemd160, hash160, hash256, taggedHash } from '@btc-vision/bitcoin';
|
|
382
|
+
|
|
383
|
+
const h = hash160(publicKey); // RIPEMD160(SHA256(data))
|
|
384
|
+
const d = hash256(data); // SHA256(SHA256(data))
|
|
385
|
+
const t = taggedHash('TapLeaf', data); // BIP340 tagged hash
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## Browser Usage
|
|
389
|
+
|
|
390
|
+
The library ships with a browser-optimized build via the `browser` conditional export. Bundlers that support the `exports` field in `package.json` (Vite, Webpack 5+, esbuild) will automatically resolve to the browser build.
|
|
391
|
+
|
|
392
|
+
For browser environments, use `createNobleBackend()` -- it is pure JavaScript with no WASM dependency. The `tiny-secp256k1` backend requires WebAssembly support and is better suited for Node.js.
|
|
393
|
+
|
|
394
|
+
## React Native
|
|
395
|
+
|
|
396
|
+
The library works in React Native with Hermes 0.76+ (BigInt and `crypto.getRandomValues()` required). The core library (PSBT, transactions, addresses, crypto) is pure JS and runs on the main thread. Parallel signing uses `react-native-worklets` when available, otherwise falls back to sequential execution automatically.
|
|
397
|
+
|
|
398
|
+
### Metro Configuration
|
|
399
|
+
|
|
400
|
+
Add `react-native` to the condition names in your `metro.config.js`:
|
|
100
401
|
|
|
101
402
|
```javascript
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
#### Alternatives for ECC Library:
|
|
109
|
-
1. `@bitcoinjs-lib/tiny-secp256k1-asmjs`
|
|
110
|
-
A version of `tiny-secp256k1` compiled to ASM.js directly from the WASM version, potentially better supported in browsers. This is the slowest option.
|
|
111
|
-
2. `@bitcoinerlab/secp256k1`
|
|
112
|
-
Another alternative library for ECC functionality. This requires access to the global `BigInt` primitive.
|
|
113
|
-
For advantages and detailed comparison of these libraries, visit: [tiny-secp256k1 GitHub page](https://github.com/bitcoinjs/tiny-secp256k1).
|
|
114
|
-
|
|
115
|
-
**NOTE**: We use Node Maintenance LTS features, if you need strict ES5, use [`--transform babelify`](https://github.com/babel/babelify) in conjunction with your `browserify` step (using an [`es2015`](https://babeljs.io/docs/plugins/preset-es2015/) preset).
|
|
116
|
-
|
|
117
|
-
**WARNING**: iOS devices have [problems](https://github.com/feross/buffer/issues/136), use at least [buffer@5.0.5](https://github.com/feross/buffer/pull/155) or greater, and enforce the test suites (for `Buffer`, and any other dependency) pass before use.
|
|
118
|
-
|
|
119
|
-
### Typescript or VSCode users
|
|
120
|
-
Type declarations for Typescript are included in this library. Normal installation should include all the needed type information.
|
|
121
|
-
|
|
122
|
-
## Examples
|
|
123
|
-
The below examples are implemented as integration tests, they should be very easy to understand.
|
|
124
|
-
Otherwise, pull requests are appreciated.
|
|
125
|
-
Some examples interact (via HTTPS) with a 3rd Party Blockchain Provider (3PBP).
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
- [Taproot Key Spend](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/taproot.spec.ts)
|
|
129
|
-
- [Generate a random address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
130
|
-
- [Import an address via WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
131
|
-
- [Generate a 2-of-3 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
132
|
-
- [Generate a SegWit address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
133
|
-
- [Generate a SegWit P2SH address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
134
|
-
- [Generate a SegWit 3-of-4 multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
135
|
-
- [Generate a SegWit 2-of-2 P2SH multisig address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
136
|
-
- [Support the retrieval of transactions for an address (3rd party blockchain)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
137
|
-
- [Generate a Testnet address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
138
|
-
- [Generate a Litecoin address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.spec.ts)
|
|
139
|
-
- [Create a 1-to-1 Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
140
|
-
- [Create (and broadcast via 3PBP) a typical Transaction](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
141
|
-
- [Create (and broadcast via 3PBP) a Transaction with an OP\_RETURN output](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
142
|
-
- [Create (and broadcast via 3PBP) a Transaction with a 2-of-4 P2SH(multisig) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
143
|
-
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2SH(P2WPKH) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
144
|
-
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2WPKH input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
145
|
-
- [Create (and broadcast via 3PBP) a Transaction with a SegWit P2PK input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
146
|
-
- [Create (and broadcast via 3PBP) a Transaction with a SegWit 3-of-4 P2SH(P2WSH(multisig)) input](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
147
|
-
- [Create (and broadcast via 3PBP) a Transaction and sign with an HDSigner interface (bip32)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/transactions.spec.ts)
|
|
148
|
-
- [Import a BIP32 testnet xpriv and export to WIF](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
149
|
-
- [Export a BIP32 xpriv, then import it](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
150
|
-
- [Export a BIP32 xpub](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
151
|
-
- [Create a BIP32, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
152
|
-
- [Create a BIP44, bitcoin, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
153
|
-
- [Create a BIP49, bitcoin testnet, account 0, external address](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
154
|
-
- [Use BIP39 to generate BIP32 addresses](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/bip32.spec.ts)
|
|
155
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the past)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
|
|
156
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
|
|
157
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice and Bob can redeem the output at any time](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
|
|
158
|
-
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.spec.ts)
|
|
159
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice can redeem the output after the expiry (in the future) (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
|
|
160
|
-
- [Create (but fail to broadcast via 3PBP) a Transaction where Alice attempts to redeem before the expiry (simple CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
|
|
161
|
-
- [Create (and broadcast via 3PBP) a Transaction where Bob and Charles can send (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
|
|
162
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) and Bob can send after 2 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
|
|
163
|
-
- [Create (and broadcast via 3PBP) a Transaction where Alice (mediator) can send after 5 blocks (complex CHECKSEQUENCEVERIFY)](https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/csv.spec.ts)
|
|
164
|
-
|
|
165
|
-
If you have a use case that you feel could be listed here, please [ask for it](https://github.com/bitcoinjs/bitcoinjs-lib/issues/new)!
|
|
403
|
+
const config = {
|
|
404
|
+
resolver: {
|
|
405
|
+
unstable_conditionNames: ['react-native', 'import', 'default'],
|
|
406
|
+
},
|
|
407
|
+
};
|
|
408
|
+
```
|
|
166
409
|
|
|
410
|
+
### Usage
|
|
167
411
|
|
|
168
|
-
|
|
169
|
-
|
|
412
|
+
Usage is identical to Node.js and browsers:
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import { initEccLib, Psbt, networks } from '@btc-vision/bitcoin';
|
|
416
|
+
import { createNobleBackend, ECPairSigner } from '@btc-vision/ecpair';
|
|
417
|
+
|
|
418
|
+
// Initialize ECC (pure JS Noble backend — no WASM needed)
|
|
419
|
+
const backend = createNobleBackend();
|
|
420
|
+
initEccLib(backend);
|
|
421
|
+
|
|
422
|
+
// Create key pair, build PSBT, sign — same API as Node.js/browser
|
|
423
|
+
const keyPair = ECPairSigner.fromWIF(backend, wif, networks.bitcoin);
|
|
424
|
+
const psbt = new Psbt({ network: networks.bitcoin });
|
|
425
|
+
// ... add inputs/outputs ...
|
|
426
|
+
psbt.signAllInputs(keyPair);
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
### Parallel Signing
|
|
430
|
+
|
|
431
|
+
`signPsbtParallel()` and `createSigningPool()` support true parallel signing in React Native via [`react-native-worklets`](https://github.com/margelo/react-native-worklets) (Software Mansion, v0.7+). Each worklet runtime gets its own ECC module instance and signing tasks are distributed round-robin across runtimes.
|
|
432
|
+
|
|
433
|
+
Install the optional peer dependency to enable parallel signing:
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
npm install react-native-worklets
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Usage is identical to Node.js/browser — `createSigningPool()` detects worklets automatically:
|
|
440
|
+
|
|
441
|
+
```typescript
|
|
442
|
+
import { signPsbtParallel, createSigningPool } from '@btc-vision/bitcoin/workers';
|
|
443
|
+
|
|
444
|
+
// Automatically uses WorkletSigningPool if react-native-worklets is installed,
|
|
445
|
+
// otherwise falls back to SequentialSigningPool (main-thread, one-by-one)
|
|
446
|
+
const pool = await createSigningPool({ workerCount: 4 });
|
|
447
|
+
pool.preserveWorkers();
|
|
448
|
+
|
|
449
|
+
const result = await signPsbtParallel(psbt, keyPair, pool);
|
|
450
|
+
await pool.shutdown();
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
You can also import `WorkletSigningPool` directly for explicit control:
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
import { WorkletSigningPool } from '@btc-vision/bitcoin/workers';
|
|
457
|
+
|
|
458
|
+
const pool = WorkletSigningPool.getInstance({ workerCount: 4 });
|
|
459
|
+
pool.preserveWorkers();
|
|
460
|
+
await pool.initialize();
|
|
461
|
+
|
|
462
|
+
const result = await pool.signBatch(tasks, keyPair);
|
|
463
|
+
await pool.shutdown();
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
If `react-native-worklets` is not installed, `createSigningPool()` returns a `SequentialSigningPool` that signs inputs one-by-one on the main thread using the same API.
|
|
467
|
+
|
|
468
|
+
### Requirements
|
|
170
469
|
|
|
470
|
+
- **Hermes 0.76+** (React Native 0.76+) for BigInt and `crypto.getRandomValues()` support
|
|
471
|
+
- **`react-native-worklets` >= 0.7.0** (optional) for parallel signing across worklet runtimes
|
|
472
|
+
- `react-native-quick-crypto` is **not** required — the core library uses `@noble/hashes` and `@noble/curves` (pure JS)
|
|
473
|
+
- A future `@btc-vision/react-native-secp256k1` Nitro Module would provide native C++ performance via `initEccLib(createNativeBackend())`
|
|
171
474
|
|
|
172
|
-
|
|
475
|
+
## Running Tests
|
|
173
476
|
|
|
174
|
-
```
|
|
175
|
-
npm test
|
|
176
|
-
npm run
|
|
477
|
+
```bash
|
|
478
|
+
npm test # Full suite (lint + build + test)
|
|
479
|
+
npm run unit # Unit tests only
|
|
480
|
+
npm run integration # Integration tests
|
|
481
|
+
npm run test:browser # Browser tests (Playwright)
|
|
482
|
+
npm run bench # Benchmarks
|
|
177
483
|
```
|
|
178
484
|
|
|
179
|
-
##
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
- [BIP69](https://github.com/bitcoinjs/bip69) - Lexicographical Indexing of Transaction Inputs and Outputs
|
|
187
|
-
- [Base58](https://github.com/cryptocoinjs/bs58) - Base58 encoding/decoding
|
|
188
|
-
- [Base58 Check](https://github.com/bitcoinjs/bs58check) - Base58 check encoding/decoding
|
|
189
|
-
- [Bech32](https://github.com/bitcoinjs/bech32) - A BIP173/BIP350 compliant Bech32/Bech32m encoding library
|
|
190
|
-
- [coinselect](https://github.com/bitcoinjs/coinselect) - A fee-optimizing, transaction input selection module for bitcoinjs-lib.
|
|
191
|
-
- [merkle-lib](https://github.com/bitcoinjs/merkle-lib) - A performance conscious library for merkle root and tree calculations.
|
|
192
|
-
- [minimaldata](https://github.com/bitcoinjs/minimaldata) - A module to check bitcoin policy: SCRIPT_VERIFY_MINIMALDATA
|
|
485
|
+
## Contributing
|
|
486
|
+
|
|
487
|
+
1. Fork the repository
|
|
488
|
+
2. Create a feature branch
|
|
489
|
+
3. Make your changes
|
|
490
|
+
4. Run tests: `npm test`
|
|
491
|
+
5. Submit a pull request
|
|
193
492
|
|
|
493
|
+
## License
|
|
194
494
|
|
|
195
|
-
|
|
196
|
-
- [BCoin](https://github.com/indutny/bcoin)
|
|
197
|
-
- [Bitcore](https://github.com/bitpay/bitcore)
|
|
198
|
-
- [Cryptocoin](https://github.com/cryptocoinjs/cryptocoin)
|
|
495
|
+
[MIT](LICENSE)
|
|
199
496
|
|
|
497
|
+
## Links
|
|
200
498
|
|
|
201
|
-
|
|
499
|
+
- [GitHub](https://github.com/btc-vision/bitcoin)
|
|
500
|
+
- [npm](https://www.npmjs.com/package/@btc-vision/bitcoin)
|
|
501
|
+
- [API Documentation](https://bitcoinjs.github.io/bitcoinjs-lib/)
|