@btc-vision/bitcoin 7.0.0-alpha.1 → 7.0.0-alpha.3

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.
Files changed (180) hide show
  1. package/README.md +334 -161
  2. package/browser/address.d.ts +5 -1
  3. package/browser/address.d.ts.map +1 -1
  4. package/browser/branded.d.ts +3 -14
  5. package/browser/branded.d.ts.map +1 -1
  6. package/browser/ecc/context.d.ts +22 -21
  7. package/browser/ecc/context.d.ts.map +1 -1
  8. package/browser/ecc/index.d.ts +1 -1
  9. package/browser/ecc/index.d.ts.map +1 -1
  10. package/browser/ecc/types.d.ts +10 -123
  11. package/browser/ecc/types.d.ts.map +1 -1
  12. package/browser/index.d.ts +3 -2
  13. package/browser/index.d.ts.map +1 -1
  14. package/browser/index.js +6465 -4692
  15. package/browser/opcodes.d.ts +11 -0
  16. package/browser/opcodes.d.ts.map +1 -1
  17. package/browser/payments/p2tr.d.ts.map +1 -1
  18. package/browser/psbt/PsbtCache.d.ts +54 -0
  19. package/browser/psbt/PsbtCache.d.ts.map +1 -0
  20. package/browser/psbt/PsbtFinalizer.d.ts +21 -0
  21. package/browser/psbt/PsbtFinalizer.d.ts.map +1 -0
  22. package/browser/psbt/PsbtSigner.d.ts +32 -0
  23. package/browser/psbt/PsbtSigner.d.ts.map +1 -0
  24. package/browser/psbt/PsbtTransaction.d.ts +25 -0
  25. package/browser/psbt/PsbtTransaction.d.ts.map +1 -0
  26. package/browser/psbt/types.d.ts +4 -70
  27. package/browser/psbt/types.d.ts.map +1 -1
  28. package/browser/psbt/validation.d.ts +1 -1
  29. package/browser/psbt/validation.d.ts.map +1 -1
  30. package/browser/psbt.d.ts +26 -40
  31. package/browser/psbt.d.ts.map +1 -1
  32. package/browser/script.d.ts.map +1 -1
  33. package/browser/transaction.d.ts +4 -4
  34. package/browser/transaction.d.ts.map +1 -1
  35. package/browser/types.d.ts +5 -3
  36. package/browser/types.d.ts.map +1 -1
  37. package/browser/workers/index.d.ts +3 -50
  38. package/browser/workers/index.d.ts.map +1 -1
  39. package/browser/workers/index.node.d.ts +24 -0
  40. package/browser/workers/index.node.d.ts.map +1 -0
  41. package/build/address.d.ts +5 -1
  42. package/build/address.d.ts.map +1 -1
  43. package/build/address.js +29 -17
  44. package/build/address.js.map +1 -1
  45. package/build/branded.d.ts +3 -14
  46. package/build/branded.d.ts.map +1 -1
  47. package/build/branded.js +0 -5
  48. package/build/branded.js.map +1 -1
  49. package/build/ecc/context.d.ts +22 -21
  50. package/build/ecc/context.d.ts.map +1 -1
  51. package/build/ecc/context.js +23 -95
  52. package/build/ecc/context.js.map +1 -1
  53. package/build/ecc/index.d.ts +1 -1
  54. package/build/ecc/index.d.ts.map +1 -1
  55. package/build/ecc/types.d.ts +7 -126
  56. package/build/ecc/types.d.ts.map +1 -1
  57. package/build/ecc/types.js +4 -1
  58. package/build/ecc/types.js.map +1 -1
  59. package/build/index.d.ts +3 -2
  60. package/build/index.d.ts.map +1 -1
  61. package/build/index.js +1 -1
  62. package/build/index.js.map +1 -1
  63. package/build/opcodes.d.ts +11 -0
  64. package/build/opcodes.d.ts.map +1 -1
  65. package/build/opcodes.js +19 -4
  66. package/build/opcodes.js.map +1 -1
  67. package/build/payments/p2tr.d.ts.map +1 -1
  68. package/build/payments/p2tr.js +2 -3
  69. package/build/payments/p2tr.js.map +1 -1
  70. package/build/psbt/PsbtCache.d.ts +54 -0
  71. package/build/psbt/PsbtCache.d.ts.map +1 -0
  72. package/build/psbt/PsbtCache.js +249 -0
  73. package/build/psbt/PsbtCache.js.map +1 -0
  74. package/build/psbt/PsbtFinalizer.d.ts +21 -0
  75. package/build/psbt/PsbtFinalizer.d.ts.map +1 -0
  76. package/build/psbt/PsbtFinalizer.js +157 -0
  77. package/build/psbt/PsbtFinalizer.js.map +1 -0
  78. package/build/psbt/PsbtSigner.d.ts +32 -0
  79. package/build/psbt/PsbtSigner.d.ts.map +1 -0
  80. package/build/psbt/PsbtSigner.js +192 -0
  81. package/build/psbt/PsbtSigner.js.map +1 -0
  82. package/build/psbt/PsbtTransaction.d.ts +25 -0
  83. package/build/psbt/PsbtTransaction.d.ts.map +1 -0
  84. package/build/psbt/PsbtTransaction.js +61 -0
  85. package/build/psbt/PsbtTransaction.js.map +1 -0
  86. package/build/psbt/types.d.ts +4 -70
  87. package/build/psbt/types.d.ts.map +1 -1
  88. package/build/psbt/validation.d.ts +1 -1
  89. package/build/psbt/validation.d.ts.map +1 -1
  90. package/build/psbt.d.ts +26 -40
  91. package/build/psbt.d.ts.map +1 -1
  92. package/build/psbt.js +177 -799
  93. package/build/psbt.js.map +1 -1
  94. package/build/script.d.ts.map +1 -1
  95. package/build/script.js +2 -2
  96. package/build/script.js.map +1 -1
  97. package/build/transaction.d.ts +4 -4
  98. package/build/transaction.d.ts.map +1 -1
  99. package/build/transaction.js +5 -4
  100. package/build/transaction.js.map +1 -1
  101. package/build/tsconfig.build.tsbuildinfo +1 -1
  102. package/build/types.d.ts +5 -3
  103. package/build/types.d.ts.map +1 -1
  104. package/build/types.js +9 -0
  105. package/build/types.js.map +1 -1
  106. package/build/workers/WorkerSigningPool.js +1 -1
  107. package/build/workers/WorkerSigningPool.js.map +1 -1
  108. package/build/workers/index.d.ts +3 -3
  109. package/build/workers/index.d.ts.map +1 -1
  110. package/build/workers/index.js +0 -3
  111. package/build/workers/index.js.map +1 -1
  112. package/build/workers/index.node.d.ts +24 -0
  113. package/build/workers/index.node.d.ts.map +1 -0
  114. package/build/workers/index.node.js +26 -0
  115. package/build/workers/index.node.js.map +1 -0
  116. package/package.json +27 -8
  117. package/src/address.ts +41 -18
  118. package/src/branded.ts +15 -13
  119. package/src/ecc/context.ts +30 -133
  120. package/src/ecc/index.ts +2 -2
  121. package/src/ecc/types.ts +7 -138
  122. package/src/index.ts +36 -2
  123. package/src/opcodes.ts +21 -4
  124. package/src/payments/p2tr.ts +2 -2
  125. package/src/psbt/PsbtCache.ts +325 -0
  126. package/src/psbt/PsbtFinalizer.ts +213 -0
  127. package/src/psbt/PsbtSigner.ts +302 -0
  128. package/src/psbt/PsbtTransaction.ts +82 -0
  129. package/src/psbt/types.ts +4 -86
  130. package/src/psbt/validation.ts +1 -1
  131. package/src/psbt.ts +348 -1197
  132. package/src/script.ts +2 -2
  133. package/src/transaction.ts +9 -8
  134. package/src/types.ts +14 -1
  135. package/src/workers/WorkerSigningPool.ts +1 -1
  136. package/src/workers/index.node.ts +27 -0
  137. package/src/workers/index.ts +7 -9
  138. package/test/address.spec.ts +2 -2
  139. package/test/bitcoin.core.spec.ts +5 -2
  140. package/test/browser/payments.spec.ts +151 -0
  141. package/test/browser/psbt.spec.ts +1510 -0
  142. package/test/browser/script.spec.ts +223 -0
  143. package/test/browser/setup.ts +13 -0
  144. package/test/browser/workers-signing.spec.ts +537 -0
  145. package/test/crypto.spec.ts +2 -2
  146. package/test/fixtures/core/base58_encode_decode.json +12 -48
  147. package/test/fixtures/core/base58_keys_invalid.json +50 -150
  148. package/test/fixtures/core/sighash.json +1 -3
  149. package/test/fixtures/core/tx_valid.json +133 -501
  150. package/test/fixtures/embed.json +3 -11
  151. package/test/fixtures/p2ms.json +21 -91
  152. package/test/fixtures/p2pk.json +5 -24
  153. package/test/fixtures/p2pkh.json +7 -36
  154. package/test/fixtures/p2sh.json +8 -54
  155. package/test/fixtures/p2tr.json +2 -6
  156. package/test/fixtures/p2wpkh.json +7 -36
  157. package/test/fixtures/p2wsh.json +14 -59
  158. package/test/fixtures/psbt.json +2 -6
  159. package/test/fixtures/script.json +12 -48
  160. package/test/integration/addresses.spec.ts +11 -5
  161. package/test/integration/bip32.spec.ts +1 -1
  162. package/test/integration/cltv.spec.ts +10 -6
  163. package/test/integration/csv.spec.ts +10 -9
  164. package/test/integration/payments.spec.ts +8 -4
  165. package/test/integration/taproot.spec.ts +26 -6
  166. package/test/integration/transactions.spec.ts +22 -8
  167. package/test/payments.spec.ts +1 -1
  168. package/test/payments.utils.ts +1 -1
  169. package/test/psbt.spec.ts +250 -64
  170. package/test/script_signature.spec.ts +1 -1
  171. package/test/transaction.spec.ts +18 -5
  172. package/test/tsconfig.json +6 -20
  173. package/test/workers-pool.spec.ts +22 -23
  174. package/test/workers-signing.spec.ts +7 -3
  175. package/test/workers.spec.ts +6 -7
  176. package/typedoc.json +11 -1
  177. package/vitest.config.browser.ts +68 -0
  178. package/browser/ecpair.d.ts +0 -99
  179. package/src/ecpair.d.ts +0 -99
  180. package/test/taproot-cache.spec.ts +0 -694
package/README.md CHANGED
@@ -1,201 +1,374 @@
1
- # BitcoinJS (bitcoinjs-lib)
2
- [![Github CI](https://github.com/bitcoinjs/bitcoinjs-lib/actions/workflows/main_ci.yml/badge.svg)](https://github.com/bitcoinjs/bitcoinjs-lib/actions/workflows/main_ci.yml) [![NPM](https://img.shields.io/npm/v/bitcoinjs-lib.svg)](https://www.npmjs.org/package/bitcoinjs-lib) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
1
+ # @btc-vision/bitcoin
3
2
 
4
- A javascript Bitcoin library for node.js and browsers. Written in TypeScript, but committing the JS files to verify.
3
+ ![Bitcoin](https://img.shields.io/badge/Bitcoin-000?style=for-the-badge&logo=bitcoin&logoColor=white)
4
+ ![TypeScript](https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white)
5
+ ![NodeJS](https://img.shields.io/badge/Node%20js-339933?style=for-the-badge&logo=nodedotjs&logoColor=white)
6
+ ![NPM](https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white)
5
7
 
6
- Released under the terms of the [MIT LICENSE](LICENSE).
8
+ [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
7
9
 
8
- ## Should I use this in production?
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
- ## Can I trust this code?
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
- We recommend every user of this library and the [bitcoinjs](https://github.com/bitcoinjs) ecosystem audit and verify any underlying code for its validity and suitability, including reviewing any and all of your project's dependencies.
14
+ This is a modernized fork of [bitcoinjs-lib](https://github.com/bitcoinjs/bitcoinjs-lib) with significant API changes:
16
15
 
17
- Mistakes and bugs happen, but with your help in resolving and reporting [issues](https://github.com/bitcoinjs/bitcoinjs-lib/issues), together we can produce open source software that is:
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
- - Easy to audit and verify,
20
- - Tested, with test coverage >95%,
21
- - Advanced and feature rich,
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
- ## Documentation
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
- You can find a [Web UI](https://bitcoincore.tech/apps/bitcoinjs-ui/index.html) that covers most of the `psbt.ts`, `transaction.ts` and `p2*.ts` APIs [here](https://bitcoincore.tech/apps/bitcoinjs-ui/index.html).
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
- ## How can I contact the developers outside of Github?
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
- That said, sometimes developers might be open to taking things off the record (ie. You want to share code that you don't want public to get help with it). In that case, please negotiate on the public issues as to where you will contact.
41
+ ## Quick Start
34
42
 
35
- We have created public rooms on IRC (`#bitcoinjs` on `libera.chat`) and Matrix (`#bitcoinjs-dev:matrix.org`). These two channels have been joined together in a Matrix "Space" which has the Matrix room AND an IRC bridge room that can converse with the IRC room. The "Space" is `#bitcoinjs-space:matrix.org`.
43
+ ### Initialize the ECC Library
36
44
 
37
- Matrix and IRC both have functions for direct messaging, but IRC is not end to end encrypted, so Matrix is recommended for most communication. The official Matrix client maintained by the Matrix core team is called "Element" and can be downloaded here: https://element.io/download (Account creation is free on the matrix.org server, which is the default setting for Element.)
45
+ The ECC library must be initialized before using Taproot, signing, or any elliptic curve operations.
38
46
 
39
- We used to have a Slack. It is dead. If you find it, no one will answer you most likely.
47
+ ```typescript
48
+ import { initEccLib } from '@btc-vision/bitcoin';
49
+ import type { EccLib } from '@btc-vision/bitcoin';
50
+ import * as ecc from 'tiny-secp256k1';
40
51
 
41
- No we will not make a Discord.
52
+ initEccLib(ecc as unknown as EccLib);
53
+ ```
42
54
 
43
- ## Installation
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
55
+ ### Create a Key Pair
56
+
57
+ ```typescript
58
+ import { ECPairSigner, createNobleBackend } from '@btc-vision/ecpair';
59
+ import { networks } from '@btc-vision/bitcoin';
60
+
61
+ const backend = createNobleBackend();
62
+
63
+ // Random key pair
64
+ const keyPair = ECPairSigner.makeRandom(backend, networks.bitcoin);
65
+
66
+ // From WIF
67
+ const imported = ECPairSigner.fromWIF(
68
+ backend,
69
+ 'L2uPYXe17xSTqbCjZvL2DsyXPCbXspvcu5mHLDYUgzdUbZGSKrSr',
70
+ networks.bitcoin,
71
+ );
72
+ ```
73
+
74
+ ### Generate Addresses
75
+
76
+ ```typescript
77
+ import { payments, networks } from '@btc-vision/bitcoin';
78
+
79
+ // P2PKH (Legacy)
80
+ const { address: legacy } = payments.p2pkh({ pubkey: keyPair.publicKey });
81
+
82
+ // P2WPKH (Native SegWit)
83
+ const { address: segwit } = payments.p2wpkh({ pubkey: keyPair.publicKey });
84
+
85
+ // P2TR (Taproot) - requires ECC initialization
86
+ import { toXOnly } from '@btc-vision/bitcoin';
87
+ const { address: taproot } = payments.p2tr({
88
+ internalPubkey: toXOnly(keyPair.publicKey),
89
+ });
90
+
91
+ // P2SH-P2WPKH (Wrapped SegWit)
92
+ const { address: wrapped } = payments.p2sh({
93
+ redeem: payments.p2wpkh({ pubkey: keyPair.publicKey }),
94
+ });
95
+
96
+ // P2SH Multisig (2-of-3)
97
+ const { address: multisig } = payments.p2sh({
98
+ redeem: payments.p2ms({ m: 2, pubkeys: [pubkey1, pubkey2, pubkey3] }),
99
+ });
100
+ ```
101
+
102
+ ### Create and Sign a Transaction (PSBT)
103
+
104
+ ```typescript
105
+ import { Psbt, networks } from '@btc-vision/bitcoin';
106
+ import { fromHex } from '@btc-vision/bitcoin';
107
+ import type { Satoshi } from '@btc-vision/bitcoin';
108
+
109
+ const psbt = new Psbt({ network: networks.bitcoin });
110
+
111
+ // Add input
112
+ psbt.addInput({
113
+ hash: '7d067b4a697a09d2c3cff7d4d9506c9955e93bff41bf82d439da7d030382bc3e',
114
+ index: 0,
115
+ nonWitnessUtxo: fromHex('0200000001...'),
116
+ sighashType: 1,
117
+ });
118
+
119
+ // Add output (values are bigint)
120
+ psbt.addOutput({
121
+ address: '1KRMKfeZcmosxALVYESdPNez1AP1mEtywp',
122
+ value: 80_000n as Satoshi,
123
+ });
124
+
125
+ // Sign, finalize, and extract
126
+ psbt.signInput(0, keyPair);
127
+ psbt.finalizeAllInputs();
128
+ const txHex = psbt.extractTransaction().toHex();
129
+ ```
130
+
131
+ ### Async Signing
132
+
133
+ ```typescript
134
+ await psbt.signInputAsync(0, keyPair);
135
+ await psbt.signAllInputsAsync(keyPair);
50
136
  ```
51
137
 
52
- Previous versions of the library included classes for key management (ECPair, HDNode(->"bip32")) but now these have been separated into different libraries. This lowers the bundle size significantly if you don't need to perform any crypto functions (converting private to public keys and deriving HD keys).
138
+ ### Parse a Transaction
53
139
 
54
- Typically we support the [Node Maintenance LTS version](https://github.com/nodejs/Release). TypeScript target will be set
55
- to the ECMAScript version in which all features are fully supported by current Active Node LTS.
56
- However, depending on adoption among other environments (browsers etc.) we may keep the target back a year or two.
57
- If in doubt, see the [main_ci.yml](.github/workflows/main_ci.yml) for what versions are used by our continuous integration tests.
140
+ ```typescript
141
+ import { Transaction } from '@btc-vision/bitcoin';
58
142
 
59
- **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.
143
+ const tx = Transaction.fromHex('0200000001...');
144
+ console.log(tx.version); // 2
145
+ console.log(tx.ins.length); // number of inputs
146
+ console.log(tx.outs.length); // number of outputs
147
+ console.log(tx.toHex()); // round-trip back to hex
148
+ ```
60
149
 
150
+ ### Decode and Encode Addresses
61
151
 
62
- ## Usage
63
- Crypto is hard.
152
+ ```typescript
153
+ import { address, networks } from '@btc-vision/bitcoin';
64
154
 
65
- When working with private keys, the random number generator is fundamentally one of the most important parts of any software you write.
66
- For random number generation, we *default* to the [`randombytes`](https://github.com/crypto-browserify/randombytes) module, which uses [`window.crypto.getRandomValues`](https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues) in the browser, or Node js' [`crypto.randomBytes`](https://nodejs.org/api/crypto.html#crypto_crypto_randombytes_size_callback), depending on your build system.
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.
155
+ // Decode any address to its output script
156
+ const outputScript = address.toOutputScript(
157
+ 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',
158
+ networks.bitcoin,
159
+ );
69
160
 
70
- This library uses [tiny-secp256k1](https://github.com/bitcoinjs/tiny-secp256k1), which uses [RFC6979](https://tools.ietf.org/html/rfc6979) to help prevent `k` re-use and exploitation.
71
- Unfortunately, this isn't a silver bullet.
72
- Often, Javascript itself is working against us by bypassing these counter-measures.
161
+ // Convert output script back to address
162
+ const addr = address.fromOutputScript(outputScript, networks.bitcoin);
73
163
 
74
- Problems in [`Buffer (UInt8Array)`](https://github.com/feross/buffer), for example, can trivially result in **catastrophic fund loss** without any warning.
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.
164
+ // Low-level Base58Check
165
+ const { hash, version } = address.fromBase58Check('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
166
+ const encoded = address.toBase58Check(hash, version);
77
167
 
78
- Finally, **adhere to best practice**.
79
- We are not an authoritative source of best practice, but, at the very least:
168
+ // Low-level Bech32
169
+ const decoded = address.fromBech32('bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4');
170
+ const bech32Addr = address.toBech32(decoded.data, decoded.version, 'bc');
171
+ ```
80
172
 
81
- * [Don't reuse addresses](https://en.bitcoin.it/wiki/Address_reuse).
82
- * Don't share BIP32 extended public keys ('xpubs'). [They are a liability](https://bitcoin.stackexchange.com/questions/56916/derivation-of-parent-private-key-from-non-hardened-child), and it only takes 1 misplaced private key (or a buggy implementation!) and you are vulnerable to **catastrophic fund loss**.
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.
173
+ ### Parallel Signing with Workers
174
+
175
+ For high-throughput signing across many inputs, use the worker pool:
176
+
177
+ ```typescript
178
+ import { createSigningPool, SignatureType } from '@btc-vision/bitcoin/workers';
179
+
180
+ // Create a platform-appropriate pool (Node.js worker_threads or Web Workers)
181
+ const pool = await createSigningPool({ workerCount: 4 });
182
+ pool.preserveWorkers();
183
+
184
+ const tasks = [
185
+ {
186
+ taskId: 'input-0',
187
+ inputIndex: 0,
188
+ hash: sighash0,
189
+ signatureType: SignatureType.ECDSA,
190
+ sighashType: 0x01,
191
+ },
192
+ {
193
+ taskId: 'input-1',
194
+ inputIndex: 1,
195
+ hash: sighash1,
196
+ signatureType: SignatureType.Schnorr,
197
+ sighashType: 0x00,
198
+ },
199
+ ];
200
+
201
+ const result = await pool.signBatch(tasks, keyPair);
202
+ if (result.success) {
203
+ console.log(`Signed ${result.signatures.size} inputs in ${result.durationMs}ms`);
204
+ }
205
+
206
+ // Or sign a PSBT directly in parallel
207
+ import { signPsbtParallel } from '@btc-vision/bitcoin/workers';
208
+ await signPsbtParallel(psbt, keyPair, pool);
209
+
210
+ await pool.shutdown();
211
+ ```
87
212
 
213
+ ## API Reference
214
+
215
+ ### Exports
216
+
217
+ The library provides granular sub-path exports for tree-shaking:
218
+
219
+ ```typescript
220
+ import { ... } from '@btc-vision/bitcoin'; // Full API
221
+ import { ... } from '@btc-vision/bitcoin/address'; // Address encoding/decoding
222
+ import { ... } from '@btc-vision/bitcoin/script'; // Script compile/decompile
223
+ import { ... } from '@btc-vision/bitcoin/crypto'; // Hash functions
224
+ import { ... } from '@btc-vision/bitcoin/transaction';// Transaction class
225
+ import { ... } from '@btc-vision/bitcoin/psbt'; // PSBT classes
226
+ import { ... } from '@btc-vision/bitcoin/networks'; // Network definitions
227
+ import { ... } from '@btc-vision/bitcoin/payments'; // Payment creators
228
+ import { ... } from '@btc-vision/bitcoin/io'; // Binary I/O utilities
229
+ import { ... } from '@btc-vision/bitcoin/ecc'; // ECC context
230
+ import { ... } from '@btc-vision/bitcoin/types'; // Type definitions & guards
231
+ import { ... } from '@btc-vision/bitcoin/errors'; // Error classes
232
+ import { ... } from '@btc-vision/bitcoin/workers'; // Parallel signing
233
+ ```
88
234
 
89
- ### Browser
90
- The recommended method of using `bitcoinjs-lib` in your browser is through [browserify](http://browserify.org/).
235
+ ### Branded Types
236
+
237
+ Values use branded types to prevent accidental misuse:
238
+
239
+ ```typescript
240
+ import type {
241
+ Bytes32, // 32-byte Uint8Array (tx hashes, witness programs)
242
+ Bytes20, // 20-byte Uint8Array (pubkey hashes)
243
+ PublicKey, // Compressed/uncompressed public key
244
+ XOnlyPublicKey, // 32-byte x-only pubkey (Taproot)
245
+ PrivateKey, // 32-byte private key
246
+ Satoshi, // bigint value (0 to 21e14)
247
+ Signature, // DER-encoded ECDSA signature
248
+ SchnorrSignature, // 64-byte Schnorr signature
249
+ Script, // Compiled script bytes
250
+ } from '@btc-vision/bitcoin';
251
+
252
+ // Type guards
253
+ import {
254
+ isBytes32, isBytes20, isPoint, isSatoshi,
255
+ isPrivateKey, isSignature, isSchnorrSignature,
256
+ isXOnlyPublicKey, isScript,
257
+ } from '@btc-vision/bitcoin';
258
+
259
+ // Conversion helpers (throw on invalid input)
260
+ import { toBytes32, toBytes20, toSatoshi } from '@btc-vision/bitcoin';
261
+ ```
91
262
 
92
- If you'd like to use a different (more modern) build tool than `browserify`, you can compile just this library and its dependencies into a single JavaScript file:
263
+ ### Payment Types
264
+
265
+ | Type | Function | Class | Description |
266
+ |------|----------|-------|-------------|
267
+ | P2PK | `p2pk()` | `P2PK` | Pay-to-Public-Key |
268
+ | P2PKH | `p2pkh()` | `P2PKH` | Pay-to-Public-Key-Hash (Legacy) |
269
+ | P2SH | `p2sh()` | `P2SH` | Pay-to-Script-Hash |
270
+ | P2MS | `p2ms()` | `P2MS` | Pay-to-Multisig |
271
+ | P2WPKH | `p2wpkh()` | `P2WPKH` | SegWit v0 Public Key Hash |
272
+ | P2WSH | `p2wsh()` | `P2WSH` | SegWit v0 Script Hash |
273
+ | P2TR | `p2tr()` | `P2TR` | Taproot (SegWit v1) |
274
+ | P2OP | `p2op()` | `P2OP` | OPNet (SegWit v16) |
275
+ | Embed | `p2data()` | `Embed` | OP_RETURN data |
276
+
277
+ ### Network Support
278
+
279
+ | Network | Constant | Bech32 Prefix |
280
+ |---------|----------|---------------|
281
+ | Bitcoin Mainnet | `networks.bitcoin` | `bc` |
282
+ | Bitcoin Testnet | `networks.testnet` | `tb` |
283
+ | Bitcoin Regtest | `networks.regtest` | `bcrt` |
284
+ | Dogecoin | `networks.dogecoin` | - |
285
+ | Litecoin | `networks.litecoin` | `ltc` |
286
+ | Bitcoin Cash | `networks.bitcoinCash` | `bitcoincash` |
287
+ | Dash | `networks.dash` | - |
288
+
289
+ ### Error Handling
290
+
291
+ All errors extend `BitcoinError`:
292
+
293
+ ```typescript
294
+ import {
295
+ BitcoinError, // Base class
296
+ ValidationError, // Input validation failures
297
+ InvalidInputError, // Invalid transaction input
298
+ InvalidOutputError,// Invalid transaction output
299
+ ScriptError, // Script operation failures
300
+ PsbtError, // PSBT operation failures
301
+ EccError, // ECC library not initialized
302
+ AddressError, // Address encoding/decoding failures
303
+ SignatureError, // Signature operation failures
304
+ } from '@btc-vision/bitcoin';
305
+
306
+ try {
307
+ psbt.signInput(0, signer);
308
+ } catch (err) {
309
+ if (err instanceof PsbtError) {
310
+ // Handle PSBT-specific error
311
+ }
312
+ }
313
+ ```
93
314
 
94
- ```sh
95
- $ npm install bitcoinjs-lib browserify
96
- $ npx browserify --standalone bitcoin - -o bitcoinjs-lib.js <<<"module.exports = require('bitcoinjs-lib');"
315
+ ### Utility Functions
316
+
317
+ ```typescript
318
+ import {
319
+ toHex, fromHex, isHex, // Hex encoding
320
+ concat, equals, compare, // Buffer operations
321
+ clone, reverse, reverseCopy, // Buffer manipulation
322
+ alloc, xor, isZero, // Buffer utilities
323
+ fromUtf8, toUtf8, // UTF-8 conversion
324
+ toXOnly, // Compress pubkey to x-only (32 bytes)
325
+ decompressPublicKey, // Decompress compressed pubkey
326
+ } from '@btc-vision/bitcoin';
97
327
  ```
98
328
 
99
- Which you can then import as an ESM module:
100
-
101
- ```javascript
102
- <script type="module">import "/scripts/bitcoinjs-lib.js"</script>
103
- ````
104
-
105
- #### Using Taproot:
106
- When utilizing Taproot features with bitcoinjs-lib, you may need to include an additional ECC (Elliptic Curve Cryptography) library. The commonly used `tiny-secp256k1` library, however, might lead to compatibility issues due to its reliance on WASM (WebAssembly). The following alternatives may be used instead, though they may be significantly slower for high volume of signing and pubkey deriving operations.
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)!
329
+ ### Crypto Functions
166
330
 
331
+ ```typescript
332
+ import { sha256, sha1, ripemd160, hash160, hash256, taggedHash } from '@btc-vision/bitcoin';
167
333
 
168
- ## Contributing
169
- See [CONTRIBUTING.md](CONTRIBUTING.md).
334
+ const h = hash160(publicKey); // RIPEMD160(SHA256(data))
335
+ const d = hash256(data); // SHA256(SHA256(data))
336
+ const t = taggedHash('TapLeaf', data); // BIP340 tagged hash
337
+ ```
170
338
 
339
+ ## Browser Usage
171
340
 
172
- ### Running the test suite
341
+ 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.
173
342
 
174
- ``` bash
175
- npm test
176
- npm run-script coverage
343
+ For Taproot operations in the browser, `tiny-secp256k1` relies on WebAssembly. If WASM is unavailable, consider these alternatives:
344
+
345
+ - **`@bitcoinjs-lib/tiny-secp256k1-asmjs`** -- ASM.js fallback (slower)
346
+ - **`@bitcoinerlab/secp256k1`** -- Pure JS with `BigInt` (requires `BigInt` support)
347
+
348
+ ## Running Tests
349
+
350
+ ```bash
351
+ npm test # Full suite (lint + build + test)
352
+ npm run unit # Unit tests only
353
+ npm run integration # Integration tests
354
+ npm run test:browser # Browser tests (Playwright)
355
+ npm run bench # Benchmarks
177
356
  ```
178
357
 
179
- ## Complementing Libraries
180
- - [BIP21](https://github.com/bitcoinjs/bip21) - A BIP21 compatible URL encoding library
181
- - [BIP38](https://github.com/bitcoinjs/bip38) - Passphrase-protected private keys
182
- - [BIP39](https://github.com/bitcoinjs/bip39) - Mnemonic generation for deterministic keys
183
- - [BIP32-Utils](https://github.com/bitcoinjs/bip32-utils) - A set of utilities for working with BIP32
184
- - [BIP66](https://github.com/bitcoinjs/bip66) - Strict DER signature decoding
185
- - [BIP68](https://github.com/bitcoinjs/bip68) - Relative lock-time encoding library
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
193
-
194
-
195
- ## Alternatives
196
- - [BCoin](https://github.com/indutny/bcoin)
197
- - [Bitcore](https://github.com/bitpay/bitcore)
198
- - [Cryptocoin](https://github.com/cryptocoinjs/cryptocoin)
199
-
200
-
201
- ## LICENSE [MIT](LICENSE)
358
+ ## Contributing
359
+
360
+ 1. Fork the repository
361
+ 2. Create a feature branch
362
+ 3. Make your changes
363
+ 4. Run tests: `npm test`
364
+ 5. Submit a pull request
365
+
366
+ ## License
367
+
368
+ [MIT](LICENSE)
369
+
370
+ ## Links
371
+
372
+ - [GitHub](https://github.com/btc-vision/bitcoin)
373
+ - [npm](https://www.npmjs.com/package/@btc-vision/bitcoin)
374
+ - [API Documentation](https://bitcoinjs.github.io/bitcoinjs-lib/)
@@ -40,7 +40,11 @@ export declare function toBase58Check(hash: Bytes20, version: number): string;
40
40
  */
41
41
  export declare function toBech32(data: Uint8Array, version: number, prefix: string, prefixOpnet?: string): string;
42
42
  /**
43
- * decode address from output script with network, return address if matched
43
+ * decode address from output script with network, return address if matched.
44
+ *
45
+ * Uses fast byte-pattern matching for common script types (P2PKH, P2SH,
46
+ * P2WPKH, P2WSH, P2TR) to avoid constructing payment objects and catching
47
+ * exceptions. Falls back to payment constructors for exotic types.
44
48
  */
45
49
  export declare function fromOutputScript(output: Uint8Array, network?: Network): string;
46
50
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAU7C,OAAO,EACH,KAAK,OAAO,EAOf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,CAAC;AAEzC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAW,CAAC;AACjD,eAAO,MAAM,sBAAsB,EAAE,MAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAE,MAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAE,MAAW,CAAC;AAC7C,eAAO,MAAM,oBAAoB,EAAE,MAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,EAAE,MAAU,CAAC;AACnD,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAOvD,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU,KAAG,OAkB3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAoCjF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAWlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CASpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CA2B9E;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,UAAU,CAwEZ"}
1
+ {"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/address.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAU7C,OAAO,EACH,KAAK,OAAO,EAMf,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,UAAU,EAAE,KAAK,YAAY,EAAE,CAAC;AAEzC,gCAAgC;AAChC,MAAM,WAAW,iBAAiB;IAC9B,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,qDAAqD;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC5B;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAW,CAAC;AACjD,eAAO,MAAM,sBAAsB,EAAE,MAAU,CAAC;AAChD,eAAO,MAAM,yBAAyB,EAAE,MAAW,CAAC;AACpD,eAAO,MAAM,kBAAkB,EAAE,MAAW,CAAC;AAC7C,eAAO,MAAM,oBAAoB,EAAE,MAAW,CAAC;AAC/C,eAAO,MAAM,yBAAyB,EAAE,MAAU,CAAC;AACnD,eAAO,MAAM,0BAA0B,EAAE,MAAa,CAAC;AAOvD,eAAO,MAAM,sBAAsB,GAAI,QAAQ,UAAU,KAAG,OAkB3D,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAoCjF;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,CAgBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,iBAAiB,CAWlE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CASpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACpB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,MAAM,GACrB,MAAM,CASR;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,MAAM,CA+C9E;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,MAAM,EACf,gBAAgB,CAAC,EAAE,OAAO,GAAG,qBAAqB,GACnD,UAAU,CAwEZ"}
@@ -1,20 +1,9 @@
1
1
  /**
2
2
  * Branded type definitions for type-safe primitives.
3
3
  *
4
+ * Re-exported from @btc-vision/ecpair to ensure cross-package type compatibility.
5
+ *
4
6
  * @packageDocumentation
5
7
  */
6
- declare const __brand: unique symbol;
7
- type Brand<T, B extends string> = T & {
8
- readonly [__brand]: B;
9
- };
10
- export type Bytes32 = Brand<Uint8Array, 'Bytes32'>;
11
- export type Bytes20 = Brand<Uint8Array, 'Bytes20'>;
12
- export type PublicKey = Brand<Uint8Array, 'PublicKey'>;
13
- export type XOnlyPublicKey = Brand<Uint8Array, 'XOnlyPublicKey'>;
14
- export type Satoshi = Brand<bigint, 'Satoshi'>;
15
- export type PrivateKey = Brand<Uint8Array, 'PrivateKey'>;
16
- export type Signature = Brand<Uint8Array, 'Signature'>;
17
- export type SchnorrSignature = Brand<Uint8Array, 'SchnorrSignature'>;
18
- export type Script = Brand<Uint8Array, 'Script'>;
19
- export {};
8
+ export type { Brand, Bytes32, Bytes20, PublicKey, XOnlyPublicKey, Satoshi, PrivateKey, Signature, SchnorrSignature, MessageHash, Script, } from '@btc-vision/ecpair';
20
9
  //# sourceMappingURL=branded.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,CAAC,MAAM,OAAO,EAAE,OAAO,MAAM,CAAC;AACrC,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAEhE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;AACnD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;AACjE,MAAM,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;AACvD,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;AACrE,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC"}
1
+ {"version":3,"file":"branded.d.ts","sourceRoot":"","sources":["../src/branded.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,YAAY,EACR,KAAK,EACL,OAAO,EACP,OAAO,EACP,SAAS,EACT,cAAc,EACd,OAAO,EACP,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,WAAW,EACX,MAAM,GACT,MAAM,oBAAoB,CAAC"}