xpi-ts 0.2.13 → 0.2.15

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 (277) hide show
  1. package/dist/cjs/lib/bitcore/address.js +75 -74
  2. package/dist/cjs/lib/bitcore/block/block.js +124 -126
  3. package/dist/cjs/lib/bitcore/block/blockheader.js +142 -208
  4. package/dist/cjs/lib/bitcore/block/index.js +3 -1
  5. package/dist/cjs/lib/bitcore/block/merkleblock.js +301 -0
  6. package/dist/cjs/lib/bitcore/crypto/bn.js +18 -22
  7. package/dist/cjs/lib/bitcore/crypto/ecdsa.js +50 -49
  8. package/dist/cjs/lib/bitcore/crypto/hash.js +25 -22
  9. package/dist/cjs/lib/bitcore/crypto/musig2.js +86 -92
  10. package/dist/cjs/lib/bitcore/crypto/point.js +42 -35
  11. package/dist/cjs/lib/bitcore/crypto/random.js +3 -2
  12. package/dist/cjs/lib/bitcore/crypto/schnorr.js +46 -55
  13. package/dist/cjs/lib/bitcore/crypto/signature.js +67 -55
  14. package/dist/cjs/lib/bitcore/crypto/sigtype.js +1 -1
  15. package/dist/cjs/lib/bitcore/encoding/base58.js +5 -4
  16. package/dist/cjs/lib/bitcore/encoding/base58check.js +14 -57
  17. package/dist/cjs/lib/bitcore/encoding/bufferreader.js +17 -17
  18. package/dist/cjs/lib/bitcore/encoding/bufferwriter.js +22 -26
  19. package/dist/cjs/lib/bitcore/encoding/varint.js +12 -11
  20. package/dist/cjs/lib/bitcore/errors.js +1 -0
  21. package/dist/cjs/lib/bitcore/hdprivatekey.js +74 -66
  22. package/dist/cjs/lib/bitcore/hdpublickey.js +96 -116
  23. package/dist/cjs/lib/bitcore/index.js +165 -172
  24. package/dist/cjs/lib/bitcore/message.js +36 -35
  25. package/dist/cjs/lib/bitcore/mnemonic/mnemonic.js +4 -3
  26. package/dist/cjs/lib/bitcore/mnemonic/pbkdf2.js +6 -5
  27. package/dist/cjs/lib/bitcore/mnemonic/words/french.js +2053 -0
  28. package/dist/cjs/lib/bitcore/mnemonic/words/index.js +2 -0
  29. package/dist/cjs/lib/bitcore/musig2/session.js +26 -25
  30. package/dist/cjs/lib/bitcore/musig2/signer.js +17 -16
  31. package/dist/cjs/lib/bitcore/networks.js +4 -3
  32. package/dist/cjs/lib/bitcore/opcode.js +11 -7
  33. package/dist/cjs/lib/bitcore/privatekey.js +42 -42
  34. package/dist/cjs/lib/bitcore/publickey.js +61 -57
  35. package/dist/cjs/lib/bitcore/script/interpreter/condition-stack.js +41 -0
  36. package/dist/cjs/lib/bitcore/script/interpreter/index.js +25 -0
  37. package/dist/cjs/lib/bitcore/script/interpreter/interpreter.js +1362 -0
  38. package/dist/cjs/lib/bitcore/script/interpreter/script-num.js +200 -0
  39. package/dist/cjs/lib/bitcore/script/interpreter/types.js +96 -0
  40. package/dist/cjs/lib/bitcore/{taproot.js → script/taproot.js} +107 -95
  41. package/dist/cjs/lib/bitcore/script.js +163 -104
  42. package/dist/cjs/lib/bitcore/taproot/musig2.js +51 -42
  43. package/dist/cjs/lib/bitcore/transaction/index.js +21 -21
  44. package/dist/cjs/lib/bitcore/transaction/input/multisig.js +10 -0
  45. package/dist/cjs/lib/bitcore/transaction/input/multisigscripthash.js +10 -0
  46. package/dist/cjs/lib/bitcore/transaction/input/publickey.js +10 -0
  47. package/dist/cjs/lib/bitcore/transaction/input/publickeyhash.js +10 -0
  48. package/dist/cjs/lib/bitcore/transaction/input/taproot.js +20 -0
  49. package/dist/cjs/lib/bitcore/transaction/input.js +145 -166
  50. package/dist/cjs/lib/bitcore/transaction/outpoint.js +89 -0
  51. package/dist/cjs/lib/bitcore/transaction/output.js +13 -8
  52. package/dist/cjs/lib/bitcore/transaction/sighash.js +96 -96
  53. package/dist/cjs/lib/bitcore/transaction/signature.js +39 -40
  54. package/dist/cjs/lib/bitcore/transaction/transaction.js +130 -118
  55. package/dist/cjs/lib/bitcore/transaction/unspentoutput.js +27 -23
  56. package/dist/cjs/lib/bitcore/util/bits.js +33 -0
  57. package/dist/cjs/lib/bitcore/util/buffer.js +29 -18
  58. package/dist/cjs/lib/bitcore/util/js.js +0 -3
  59. package/dist/cjs/lib/bitcore/util/merkle.js +53 -0
  60. package/dist/cjs/lib/bitcore/util/preconditions.js +8 -7
  61. package/dist/cjs/lib/bitcore/xaddress.js +27 -23
  62. package/dist/cjs/lib/{bitcore/taproot/nft.js → nft.js} +98 -29
  63. package/dist/cjs/lib/rank/index.js +28 -27
  64. package/dist/cjs/lib/rank/script.js +2 -1
  65. package/dist/cjs/lib/rank/transaction.js +2 -1
  66. package/dist/cjs/utils/string.js +6 -5
  67. package/dist/esm/lib/bitcore/address.js +42 -41
  68. package/dist/esm/lib/bitcore/block/block.js +126 -128
  69. package/dist/esm/lib/bitcore/block/blockheader.js +141 -207
  70. package/dist/esm/lib/bitcore/block/index.js +1 -0
  71. package/dist/esm/lib/bitcore/block/merkleblock.js +295 -0
  72. package/dist/esm/lib/bitcore/crypto/bn.js +18 -22
  73. package/dist/esm/lib/bitcore/crypto/ecdsa.js +25 -24
  74. package/dist/esm/lib/bitcore/crypto/hash.js +25 -22
  75. package/dist/esm/lib/bitcore/crypto/musig2.js +60 -66
  76. package/dist/esm/lib/bitcore/crypto/point.js +22 -15
  77. package/dist/esm/lib/bitcore/crypto/random.js +3 -2
  78. package/dist/esm/lib/bitcore/crypto/schnorr.js +35 -44
  79. package/dist/esm/lib/bitcore/crypto/signature.js +61 -49
  80. package/dist/esm/lib/bitcore/crypto/sigtype.js +1 -1
  81. package/dist/esm/lib/bitcore/encoding/base58.js +5 -4
  82. package/dist/esm/lib/bitcore/encoding/base58check.js +11 -57
  83. package/dist/esm/lib/bitcore/encoding/bufferreader.js +7 -7
  84. package/dist/esm/lib/bitcore/encoding/bufferwriter.js +18 -21
  85. package/dist/esm/lib/bitcore/encoding/varint.js +7 -6
  86. package/dist/esm/lib/bitcore/errors.js +1 -0
  87. package/dist/esm/lib/bitcore/hdprivatekey.js +47 -39
  88. package/dist/esm/lib/bitcore/hdpublickey.js +77 -97
  89. package/dist/esm/lib/bitcore/index.js +42 -45
  90. package/dist/esm/lib/bitcore/message.js +16 -15
  91. package/dist/esm/lib/bitcore/mnemonic/mnemonic.js +4 -3
  92. package/dist/esm/lib/bitcore/mnemonic/pbkdf2.js +5 -4
  93. package/dist/esm/lib/bitcore/mnemonic/words/french.js +2050 -0
  94. package/dist/esm/lib/bitcore/mnemonic/words/index.js +2 -0
  95. package/dist/esm/lib/bitcore/musig2/session.js +17 -16
  96. package/dist/esm/lib/bitcore/musig2/signer.js +19 -18
  97. package/dist/esm/lib/bitcore/networks.js +4 -3
  98. package/dist/esm/lib/bitcore/opcode.js +9 -5
  99. package/dist/esm/lib/bitcore/privatekey.js +25 -25
  100. package/dist/esm/lib/bitcore/publickey.js +46 -42
  101. package/dist/esm/lib/bitcore/script/interpreter/condition-stack.js +37 -0
  102. package/dist/esm/lib/bitcore/script/interpreter/index.js +4 -0
  103. package/dist/esm/lib/bitcore/script/interpreter/interpreter.js +1356 -0
  104. package/dist/esm/lib/bitcore/script/interpreter/script-num.js +195 -0
  105. package/dist/esm/lib/bitcore/script/interpreter/types.js +93 -0
  106. package/dist/esm/lib/bitcore/{taproot.js → script/taproot.js} +92 -81
  107. package/dist/esm/lib/bitcore/script.js +163 -102
  108. package/dist/esm/lib/bitcore/taproot/musig2.js +36 -27
  109. package/dist/esm/lib/bitcore/transaction/index.js +6 -6
  110. package/dist/esm/lib/bitcore/transaction/input/multisig.js +6 -0
  111. package/dist/esm/lib/bitcore/transaction/input/multisigscripthash.js +6 -0
  112. package/dist/esm/lib/bitcore/transaction/input/publickey.js +6 -0
  113. package/dist/esm/lib/bitcore/transaction/input/publickeyhash.js +6 -0
  114. package/dist/esm/lib/bitcore/transaction/input/taproot.js +16 -0
  115. package/dist/esm/lib/bitcore/transaction/input.js +55 -76
  116. package/dist/esm/lib/bitcore/transaction/outpoint.js +85 -0
  117. package/dist/esm/lib/bitcore/transaction/output.js +13 -8
  118. package/dist/esm/lib/bitcore/transaction/sighash.js +22 -22
  119. package/dist/esm/lib/bitcore/transaction/signature.js +16 -17
  120. package/dist/esm/lib/bitcore/transaction/transaction.js +58 -46
  121. package/dist/esm/lib/bitcore/transaction/unspentoutput.js +15 -11
  122. package/dist/esm/lib/bitcore/util/bits.js +27 -0
  123. package/dist/esm/lib/bitcore/util/buffer.js +20 -9
  124. package/dist/esm/lib/bitcore/util/js.js +0 -3
  125. package/dist/esm/lib/bitcore/util/merkle.js +47 -0
  126. package/dist/esm/lib/bitcore/util/preconditions.js +3 -2
  127. package/dist/esm/lib/bitcore/xaddress.js +16 -12
  128. package/dist/esm/lib/{bitcore/taproot/nft.js → nft.js} +97 -28
  129. package/dist/esm/lib/rank/index.js +15 -14
  130. package/dist/esm/lib/rank/script.js +1 -0
  131. package/dist/esm/lib/rank/transaction.js +1 -0
  132. package/dist/esm/utils/string.js +1 -0
  133. package/dist/types/lib/bitcore/address.d.ts +4 -3
  134. package/dist/types/lib/bitcore/address.d.ts.map +1 -1
  135. package/dist/types/lib/bitcore/block/block.d.ts +11 -19
  136. package/dist/types/lib/bitcore/block/block.d.ts.map +1 -1
  137. package/dist/types/lib/bitcore/block/blockheader.d.ts +30 -32
  138. package/dist/types/lib/bitcore/block/blockheader.d.ts.map +1 -1
  139. package/dist/types/lib/bitcore/block/index.d.ts +2 -0
  140. package/dist/types/lib/bitcore/block/index.d.ts.map +1 -1
  141. package/dist/types/lib/bitcore/block/merkleblock.d.ts +53 -0
  142. package/dist/types/lib/bitcore/block/merkleblock.d.ts.map +1 -0
  143. package/dist/types/lib/bitcore/crypto/bn.d.ts +2 -2
  144. package/dist/types/lib/bitcore/crypto/bn.d.ts.map +1 -1
  145. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts +5 -4
  146. package/dist/types/lib/bitcore/crypto/ecdsa.d.ts.map +1 -1
  147. package/dist/types/lib/bitcore/crypto/hash.d.ts +3 -1
  148. package/dist/types/lib/bitcore/crypto/hash.d.ts.map +1 -1
  149. package/dist/types/lib/bitcore/crypto/musig2.d.ts +22 -30
  150. package/dist/types/lib/bitcore/crypto/musig2.d.ts.map +1 -1
  151. package/dist/types/lib/bitcore/crypto/point.d.ts +8 -3
  152. package/dist/types/lib/bitcore/crypto/point.d.ts.map +1 -1
  153. package/dist/types/lib/bitcore/crypto/random.d.ts +1 -0
  154. package/dist/types/lib/bitcore/crypto/random.d.ts.map +1 -1
  155. package/dist/types/lib/bitcore/crypto/schnorr.d.ts +5 -4
  156. package/dist/types/lib/bitcore/crypto/schnorr.d.ts.map +1 -1
  157. package/dist/types/lib/bitcore/crypto/signature.d.ts +4 -1
  158. package/dist/types/lib/bitcore/crypto/signature.d.ts.map +1 -1
  159. package/dist/types/lib/bitcore/crypto/sigtype.d.ts +1 -0
  160. package/dist/types/lib/bitcore/crypto/sigtype.d.ts.map +1 -1
  161. package/dist/types/lib/bitcore/encoding/base58.d.ts +1 -0
  162. package/dist/types/lib/bitcore/encoding/base58.d.ts.map +1 -1
  163. package/dist/types/lib/bitcore/encoding/base58check.d.ts +1 -2
  164. package/dist/types/lib/bitcore/encoding/base58check.d.ts.map +1 -1
  165. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts +2 -1
  166. package/dist/types/lib/bitcore/encoding/bufferreader.d.ts.map +1 -1
  167. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts +2 -2
  168. package/dist/types/lib/bitcore/encoding/bufferwriter.d.ts.map +1 -1
  169. package/dist/types/lib/bitcore/encoding/varint.d.ts +3 -2
  170. package/dist/types/lib/bitcore/encoding/varint.d.ts.map +1 -1
  171. package/dist/types/lib/bitcore/errors.d.ts +3 -0
  172. package/dist/types/lib/bitcore/errors.d.ts.map +1 -1
  173. package/dist/types/lib/bitcore/hdprivatekey.d.ts +5 -4
  174. package/dist/types/lib/bitcore/hdprivatekey.d.ts.map +1 -1
  175. package/dist/types/lib/bitcore/hdpublickey.d.ts +4 -3
  176. package/dist/types/lib/bitcore/hdpublickey.d.ts.map +1 -1
  177. package/dist/types/lib/bitcore/index.d.ts +55 -60
  178. package/dist/types/lib/bitcore/index.d.ts.map +1 -1
  179. package/dist/types/lib/bitcore/message.d.ts +7 -4
  180. package/dist/types/lib/bitcore/message.d.ts.map +1 -1
  181. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts +2 -0
  182. package/dist/types/lib/bitcore/mnemonic/mnemonic.d.ts.map +1 -1
  183. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts +1 -0
  184. package/dist/types/lib/bitcore/mnemonic/pbkdf2.d.ts.map +1 -1
  185. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts +2 -0
  186. package/dist/types/lib/bitcore/mnemonic/words/french.d.ts.map +1 -0
  187. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts +1 -0
  188. package/dist/types/lib/bitcore/mnemonic/words/index.d.ts.map +1 -1
  189. package/dist/types/lib/bitcore/musig2/session.d.ts +8 -7
  190. package/dist/types/lib/bitcore/musig2/session.d.ts.map +1 -1
  191. package/dist/types/lib/bitcore/musig2/signer.d.ts +10 -9
  192. package/dist/types/lib/bitcore/musig2/signer.d.ts.map +1 -1
  193. package/dist/types/lib/bitcore/networks.d.ts +1 -0
  194. package/dist/types/lib/bitcore/networks.d.ts.map +1 -1
  195. package/dist/types/lib/bitcore/opcode.d.ts +5 -0
  196. package/dist/types/lib/bitcore/opcode.d.ts.map +1 -1
  197. package/dist/types/lib/bitcore/privatekey.d.ts +5 -4
  198. package/dist/types/lib/bitcore/privatekey.d.ts.map +1 -1
  199. package/dist/types/lib/bitcore/publickey.d.ts +13 -6
  200. package/dist/types/lib/bitcore/publickey.d.ts.map +1 -1
  201. package/dist/types/lib/bitcore/{chunk.d.ts → script/chunk.d.ts} +1 -0
  202. package/dist/types/lib/bitcore/script/chunk.d.ts.map +1 -0
  203. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts +11 -0
  204. package/dist/types/lib/bitcore/script/interpreter/condition-stack.d.ts.map +1 -0
  205. package/dist/types/lib/bitcore/script/interpreter/index.d.ts +5 -0
  206. package/dist/types/lib/bitcore/script/interpreter/index.d.ts.map +1 -0
  207. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts +21 -0
  208. package/dist/types/lib/bitcore/script/interpreter/interpreter.d.ts.map +1 -0
  209. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts +35 -0
  210. package/dist/types/lib/bitcore/script/interpreter/script-num.d.ts.map +1 -0
  211. package/dist/types/lib/bitcore/script/interpreter/types.d.ts +101 -0
  212. package/dist/types/lib/bitcore/script/interpreter/types.d.ts.map +1 -0
  213. package/dist/types/lib/bitcore/{taproot.d.ts → script/taproot.d.ts} +20 -7
  214. package/dist/types/lib/bitcore/script/taproot.d.ts.map +1 -0
  215. package/dist/types/lib/bitcore/script.d.ts +12 -11
  216. package/dist/types/lib/bitcore/script.d.ts.map +1 -1
  217. package/dist/types/lib/bitcore/taproot/musig2.d.ts +17 -16
  218. package/dist/types/lib/bitcore/taproot/musig2.d.ts.map +1 -1
  219. package/dist/types/lib/bitcore/transaction/index.d.ts +11 -11
  220. package/dist/types/lib/bitcore/transaction/index.d.ts.map +1 -1
  221. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts +5 -0
  222. package/dist/types/lib/bitcore/transaction/input/multisig.d.ts.map +1 -0
  223. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts +5 -0
  224. package/dist/types/lib/bitcore/transaction/input/multisigscripthash.d.ts.map +1 -0
  225. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts +5 -0
  226. package/dist/types/lib/bitcore/transaction/input/publickey.d.ts.map +1 -0
  227. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts +6 -0
  228. package/dist/types/lib/bitcore/transaction/input/publickeyhash.d.ts.map +1 -0
  229. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts +18 -0
  230. package/dist/types/lib/bitcore/transaction/input/taproot.d.ts.map +1 -0
  231. package/dist/types/lib/bitcore/transaction/input.d.ts +27 -35
  232. package/dist/types/lib/bitcore/transaction/input.d.ts.map +1 -1
  233. package/dist/types/lib/bitcore/transaction/outpoint.d.ts +32 -0
  234. package/dist/types/lib/bitcore/transaction/outpoint.d.ts.map +1 -0
  235. package/dist/types/lib/bitcore/transaction/output.d.ts +3 -1
  236. package/dist/types/lib/bitcore/transaction/output.d.ts.map +1 -1
  237. package/dist/types/lib/bitcore/transaction/sighash.d.ts +8 -7
  238. package/dist/types/lib/bitcore/transaction/sighash.d.ts.map +1 -1
  239. package/dist/types/lib/bitcore/transaction/signature.d.ts +3 -2
  240. package/dist/types/lib/bitcore/transaction/signature.d.ts.map +1 -1
  241. package/dist/types/lib/bitcore/transaction/transaction.d.ts +18 -15
  242. package/dist/types/lib/bitcore/transaction/transaction.d.ts.map +1 -1
  243. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts +9 -7
  244. package/dist/types/lib/bitcore/transaction/unspentoutput.d.ts.map +1 -1
  245. package/dist/types/lib/bitcore/unit.d.ts.map +1 -1
  246. package/dist/types/lib/bitcore/util/base32.d.ts.map +1 -1
  247. package/dist/types/lib/bitcore/util/bits.d.ts +5 -0
  248. package/dist/types/lib/bitcore/util/bits.d.ts.map +1 -0
  249. package/dist/types/lib/bitcore/util/buffer.d.ts +10 -2
  250. package/dist/types/lib/bitcore/util/buffer.d.ts.map +1 -1
  251. package/dist/types/lib/bitcore/util/js.d.ts +0 -1
  252. package/dist/types/lib/bitcore/util/js.d.ts.map +1 -1
  253. package/dist/types/lib/bitcore/util/merkle.d.ts +6 -0
  254. package/dist/types/lib/bitcore/util/merkle.d.ts.map +1 -0
  255. package/dist/types/lib/bitcore/util/preconditions.d.ts.map +1 -1
  256. package/dist/types/lib/bitcore/xaddress.d.ts +1 -0
  257. package/dist/types/lib/bitcore/xaddress.d.ts.map +1 -1
  258. package/dist/types/lib/{bitcore/taproot/nft.d.ts → nft.d.ts} +26 -12
  259. package/dist/types/lib/nft.d.ts.map +1 -0
  260. package/dist/types/lib/rank/index.d.ts +1 -0
  261. package/dist/types/lib/rank/index.d.ts.map +1 -1
  262. package/dist/types/lib/rank/script.d.ts +1 -0
  263. package/dist/types/lib/rank/script.d.ts.map +1 -1
  264. package/dist/types/lib/rank/transaction.d.ts +1 -0
  265. package/dist/types/lib/rank/transaction.d.ts.map +1 -1
  266. package/dist/types/utils/string.d.ts +1 -0
  267. package/dist/types/utils/string.d.ts.map +1 -1
  268. package/package.json +3 -2
  269. package/dist/cjs/lib/bitcore/script/interpreter.js +0 -1757
  270. package/dist/esm/lib/bitcore/script/interpreter.js +0 -1753
  271. package/dist/types/lib/bitcore/chunk.d.ts.map +0 -1
  272. package/dist/types/lib/bitcore/script/interpreter.d.ts +0 -101
  273. package/dist/types/lib/bitcore/script/interpreter.d.ts.map +0 -1
  274. package/dist/types/lib/bitcore/taproot/nft.d.ts.map +0 -1
  275. package/dist/types/lib/bitcore/taproot.d.ts.map +0 -1
  276. /package/dist/cjs/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
  277. /package/dist/esm/lib/bitcore/{chunk.js → script/chunk.js} +0 -0
@@ -1,12 +1,13 @@
1
- import { Preconditions } from './util/preconditions.js';
2
- import { BitcoreError } from './errors.js';
3
- import { Base58Check } from './encoding/base58check.js';
4
- import { get as getNetwork, defaultNetwork, } from './networks.js';
5
- import { Hash } from './crypto/hash.js';
6
- import { JSUtil } from './util/js.js';
7
- import { PublicKey } from './publickey.js';
8
- import { XAddress } from './xaddress.js';
9
- import { Script } from './script.js';
1
+ import { Preconditions as $ } from './util/preconditions';
2
+ import { BitcoreError } from './errors';
3
+ import { Base58Check } from './encoding/base58check';
4
+ import { get as getNetwork, defaultNetwork, } from './networks';
5
+ import { Hash } from './crypto/hash';
6
+ import { JSUtil, BufferUtil } from './util';
7
+ import { PublicKey } from './publickey';
8
+ import { XAddress } from './xaddress';
9
+ import { Script } from './script';
10
+ import { Opcode } from './opcode';
10
11
  export class Address {
11
12
  static PayToPublicKeyHash = 'pubkeyhash';
12
13
  static PayToScriptHash = 'scripthash';
@@ -18,7 +19,7 @@ export class Address {
18
19
  if (data instanceof Address) {
19
20
  return data;
20
21
  }
21
- Preconditions.checkArgument(data !== undefined, 'data', 'First argument is required, please include address data.', 'guide/address.html');
22
+ $.checkArgument(data !== undefined, 'data', 'First argument is required, please include address data.', 'guide/address.html');
22
23
  if (network && !getNetwork(network)) {
23
24
  throw new TypeError('Second argument must be "livenet", "testnet", or "regtest".');
24
25
  }
@@ -47,18 +48,18 @@ export class Address {
47
48
  }
48
49
  network = networkObj;
49
50
  }
50
- if ((Buffer.isBuffer(data) || data instanceof Uint8Array) &&
51
+ if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
51
52
  data.length === 20) {
52
53
  return Address._transformHash(data);
53
54
  }
54
- else if ((Buffer.isBuffer(data) || data instanceof Uint8Array) &&
55
+ else if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
55
56
  data.length === 21) {
56
57
  return Address._transformBuffer(data, network, type);
57
58
  }
58
- else if ((Buffer.isBuffer(data) || data instanceof Uint8Array) &&
59
+ else if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
59
60
  data.length === 33) {
60
61
  return {
61
- hashBuffer: Buffer.from(data),
62
+ hashBuffer: BufferUtil.from(data),
62
63
  network: typeof network === 'string' ? getNetwork(network) : network,
63
64
  type: type || Address.PayToTaproot,
64
65
  };
@@ -112,7 +113,7 @@ export class Address {
112
113
  throw new TypeError('Address has mismatched network type.');
113
114
  }
114
115
  return {
115
- hashBuffer: Buffer.from(info.hashBuffer),
116
+ hashBuffer: BufferUtil.from(info.hashBuffer),
116
117
  network: info.network,
117
118
  type: info.type,
118
119
  };
@@ -139,7 +140,7 @@ export class Address {
139
140
  if (!version.network || !version.type) {
140
141
  throw new TypeError('Address has invalid version.');
141
142
  }
142
- info.hashBuffer = decoded.subarray(1);
143
+ info.hashBuffer = decoded.slice(1);
143
144
  info.network = version.network;
144
145
  info.type = version.type;
145
146
  return info;
@@ -162,10 +163,10 @@ export class Address {
162
163
  const decodedType = decodedXAddress.type;
163
164
  if (decodedType === 'taproot' || decodedType === Address.PayToTaproot) {
164
165
  if (hashBuffer.length === 36 &&
165
- hashBuffer[0] === 0x62 &&
166
- hashBuffer[1] === 0x51 &&
166
+ hashBuffer[0] === Opcode.OP_SCRIPTTYPE &&
167
+ hashBuffer[1] === Opcode.OP_1 &&
167
168
  hashBuffer[2] === 0x21) {
168
- hashBuffer = hashBuffer.subarray(3, 36);
169
+ hashBuffer = hashBuffer.slice(3, 36);
169
170
  }
170
171
  else if (hashBuffer.length === 33) {
171
172
  }
@@ -179,16 +180,16 @@ export class Address {
179
180
  };
180
181
  }
181
182
  if (hashBuffer.length === 25 &&
182
- hashBuffer[0] === 0x76 &&
183
- hashBuffer[1] === 0xa9 &&
183
+ hashBuffer[0] === Opcode.OP_DUP &&
184
+ hashBuffer[1] === Opcode.OP_HASH160 &&
184
185
  hashBuffer[2] === 0x14) {
185
- hashBuffer = hashBuffer.subarray(3, 23);
186
+ hashBuffer = hashBuffer.slice(3, 23);
186
187
  }
187
188
  else if (hashBuffer.length === 23 &&
188
- hashBuffer[0] === 0xa9 &&
189
+ hashBuffer[0] === Opcode.OP_HASH160 &&
189
190
  hashBuffer[1] === 0x14 &&
190
- hashBuffer[22] === 0x87) {
191
- hashBuffer = hashBuffer.subarray(2, 22);
191
+ hashBuffer[22] === Opcode.OP_EQUAL) {
192
+ hashBuffer = hashBuffer.slice(2, 22);
192
193
  return {
193
194
  hashBuffer: hashBuffer,
194
195
  network: decodedNetwork,
@@ -203,25 +204,25 @@ export class Address {
203
204
  }
204
205
  static _transformHash(hash) {
205
206
  const info = {};
206
- if (!Buffer.isBuffer(hash) && !(hash instanceof Uint8Array)) {
207
+ if (!BufferUtil.isBuffer(hash)) {
207
208
  throw new TypeError('Address supplied is not a buffer.');
208
209
  }
209
210
  if (hash.length !== 20) {
210
211
  throw new TypeError('Address hashbuffers must be exactly 20 bytes.');
211
212
  }
212
- info.hashBuffer = Buffer.from(hash);
213
+ info.hashBuffer = BufferUtil.from(hash);
213
214
  return info;
214
215
  }
215
216
  static _transformBuffer(buffer, network, type) {
216
217
  const info = {};
217
- if (!Buffer.isBuffer(buffer) && !(buffer instanceof Uint8Array)) {
218
+ if (!BufferUtil.isBuffer(buffer)) {
218
219
  throw new TypeError('Address supplied is not a buffer.');
219
220
  }
220
221
  if (buffer.length !== 21) {
221
222
  throw new TypeError('Address buffers must be exactly 21 bytes.');
222
223
  }
223
224
  const networkObj = getNetwork(network);
224
- const bufferVersion = Address._classifyFromVersion(Buffer.from(buffer));
225
+ const bufferVersion = Address._classifyFromVersion(BufferUtil.from(buffer));
225
226
  if (network && !networkObj) {
226
227
  throw new TypeError('Unknown network');
227
228
  }
@@ -232,7 +233,7 @@ export class Address {
232
233
  if (!bufferVersion.type || (type && type !== bufferVersion.type)) {
233
234
  throw new TypeError('Address has mismatched type.');
234
235
  }
235
- info.hashBuffer = Buffer.from(buffer).subarray(1);
236
+ info.hashBuffer = BufferUtil.from(buffer).slice(1);
236
237
  info.network = bufferVersion.network;
237
238
  info.type = bufferVersion.type;
238
239
  return info;
@@ -248,7 +249,7 @@ export class Address {
248
249
  return info;
249
250
  }
250
251
  static _transformScript(script, network) {
251
- Preconditions.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
252
+ $.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
252
253
  const address = script.getAddressInfo();
253
254
  if (!address) {
254
255
  throw new BitcoreError.Script.CantDeriveAddress('Cannot derive address from script');
@@ -263,10 +264,10 @@ export class Address {
263
264
  };
264
265
  }
265
266
  static _transformObject(data) {
266
- Preconditions.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
267
- Preconditions.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
267
+ $.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
268
+ $.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
268
269
  return {
269
- hashBuffer: data.hashBuffer || Buffer.from(data.hashBuffer.toString(), 'hex'),
270
+ hashBuffer: data.hashBuffer || BufferUtil.from(data.hashBuffer.toString(), 'hex'),
270
271
  network: getNetwork(data.network) || defaultNetwork,
271
272
  type: data.type,
272
273
  };
@@ -305,18 +306,18 @@ export class Address {
305
306
  return new Address(info.hashBuffer, info.network, info.type);
306
307
  }
307
308
  static fromObject(obj) {
308
- Preconditions.checkState(JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
309
- const hashBuffer = Buffer.from(obj.hash, 'hex');
309
+ $.checkState(JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
310
+ const hashBuffer = BufferUtil.from(obj.hash, 'hex');
310
311
  return new Address(hashBuffer, obj.network, obj.type);
311
312
  }
312
313
  static fromScript(script, network) {
313
- Preconditions.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
314
+ $.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
314
315
  const info = Address._transformScript(script, network);
315
316
  return new Address(info.hashBuffer, network, info.type);
316
317
  }
317
318
  static payingTo(script, network) {
318
- Preconditions.checkArgument(script !== null, 'script', 'script is required');
319
- Preconditions.checkArgument(script instanceof Script, 'script', 'script must be instance of Script');
319
+ $.checkArgument(script !== null, 'script', 'script is required');
320
+ $.checkArgument(script instanceof Script, 'script', 'script must be instance of Script');
320
321
  return Address.fromScriptHash(Hash.sha256ripemd160(script.toBuffer()), network);
321
322
  }
322
323
  static getValidationError(data, network, type) {
@@ -344,10 +345,10 @@ export class Address {
344
345
  return this.hashBuffer;
345
346
  }
346
347
  toFullBuffer() {
347
- const version = Buffer.from([
348
+ const version = BufferUtil.from([
348
349
  this.network[this.type],
349
350
  ]);
350
- const buf = Buffer.concat([version, this.hashBuffer]);
351
+ const buf = BufferUtil.concat([version, this.hashBuffer]);
351
352
  return buf;
352
353
  }
353
354
  toCashBuffer() {
@@ -1,158 +1,76 @@
1
- import { Preconditions } from '../util/preconditions.js';
2
- import { BufferUtil } from '../util/buffer.js';
1
+ import { Buffer } from 'buffer/';
2
+ import { Preconditions as $ } from '../util/preconditions.js';
3
+ import { BufferUtil, NULL_HASH } from '../util/buffer.js';
3
4
  import { BufferReader } from '../encoding/bufferreader.js';
4
5
  import { BufferWriter } from '../encoding/bufferwriter.js';
5
6
  import { Hash } from '../crypto/hash.js';
6
7
  import { JSUtil } from '../util/js.js';
7
8
  import { Transaction } from '../transaction/index.js';
8
9
  import { BN } from '../crypto/bn.js';
10
+ import { calcTreeHeight, traverseAndBuild } from '../util/merkle.js';
9
11
  import { BlockHeader, } from './blockheader.js';
12
+ import { MerkleBlock } from './merkleblock.js';
10
13
  export class Block {
11
14
  static MAX_BLOCK_SIZE = 32 * 1024 * 1024;
12
- static START_OF_BLOCK = 0;
13
- static NULL_HASH = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
14
- static Values = {
15
- START_OF_BLOCK: 0,
16
- NULL_HASH: Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
17
- };
15
+ static NULL_HASH = NULL_HASH;
18
16
  header;
19
- metadata;
20
17
  transactions;
21
18
  _id;
22
19
  constructor(serialized) {
23
- if (!(this instanceof Block)) {
24
- return new Block(serialized);
25
- }
26
20
  if (serialized instanceof Block) {
27
21
  return Block.shallowCopy(serialized);
28
22
  }
29
23
  else if (typeof serialized === 'string' && JSUtil.isHexa(serialized)) {
30
- this.fromString(serialized);
31
- }
32
- else if (Buffer.isBuffer(serialized)) {
33
- this.fromBuffer(serialized);
24
+ this._fromString(serialized);
34
25
  }
35
- else if (serialized && typeof serialized === 'object') {
36
- this.fromObject(serialized);
26
+ else if (Buffer.isBuffer(serialized) ||
27
+ (serialized && typeof serialized === 'object')) {
28
+ const info = Block._from(serialized);
29
+ this.header = info.header;
30
+ this.transactions = info.transactions;
37
31
  }
38
32
  else {
39
- this._newBlock();
33
+ this._initEmpty();
40
34
  }
41
35
  }
42
36
  static shallowCopy(block) {
43
- const copy = new Block(block.toBuffer());
44
- return copy;
45
- }
46
- static _from(arg) {
47
- let info = {};
48
- if (Buffer.isBuffer(arg)) {
49
- info = Block._fromBufferReader(new BufferReader(arg));
50
- }
51
- else if (typeof arg === 'object' && arg !== null) {
52
- info = Block._fromObject(arg);
53
- }
54
- else {
55
- throw new TypeError('Unrecognized argument for Block');
56
- }
57
- return info;
37
+ return new Block(block.toBuffer());
58
38
  }
59
39
  static fromObject(obj) {
60
40
  const info = Block._fromObject(obj);
61
41
  return new Block(info);
62
42
  }
63
43
  static fromBufferReader(br) {
64
- Preconditions.checkArgument(br instanceof BufferReader, 'br is required');
65
- const info = Block._fromBufferReader(br);
44
+ $.checkArgument(br instanceof BufferReader, 'br is required');
45
+ const info = Block._readFromBuffer(br);
66
46
  return new Block(info);
67
47
  }
68
48
  static fromBuffer(buf) {
69
49
  return Block.fromBufferReader(new BufferReader(buf));
70
50
  }
71
51
  static fromString(str) {
72
- const buf = Buffer.from(str, 'hex');
73
- return Block.fromBuffer(buf);
52
+ return Block.fromBuffer(Buffer.from(str, 'hex'));
74
53
  }
75
54
  static fromRawBlock(data) {
76
55
  if (!BufferUtil.isBuffer(data)) {
77
56
  data = Buffer.from(data, 'binary');
78
57
  }
79
58
  const br = new BufferReader(data);
80
- br.pos = Block.Values.START_OF_BLOCK;
81
- const info = Block._fromBufferReader(br);
59
+ const info = Block._readFromBuffer(br);
82
60
  return new Block(info);
83
61
  }
84
- static _fromObject(data) {
85
- const transactions = [];
86
- if (data.transactions) {
87
- data.transactions.forEach(tx => {
88
- if (tx instanceof Transaction) {
89
- transactions.push(tx);
90
- }
91
- else {
92
- transactions.push(new Transaction(tx));
93
- }
94
- });
95
- }
96
- return {
97
- header: data.header
98
- ? data.header instanceof BlockHeader
99
- ? data.header
100
- : new BlockHeader(data.header)
101
- : new BlockHeader(),
102
- metadata: data.metadata || 0x00,
103
- transactions: transactions,
104
- };
105
- }
106
- static _fromBufferReader(br) {
107
- Preconditions.checkState(!br.finished(), 'No block data received');
108
- const header = BlockHeader.fromBufferReader(br);
109
- const metadata = br.readUInt8();
110
- const transactionCount = br.readVarintNum();
111
- const transactions = [];
112
- for (let i = 0; i < transactionCount; i++) {
113
- const tx = new Transaction();
114
- transactions.push(tx.fromBufferReader(br));
115
- }
116
- return {
117
- header,
118
- metadata,
119
- transactions,
120
- };
121
- }
122
- _newBlock() {
123
- this.header = new BlockHeader();
124
- this.metadata = 0x00;
125
- this.transactions = [];
126
- }
127
- fromBuffer(buf) {
128
- const info = Block._fromBufferReader(new BufferReader(buf));
129
- this.header = info.header;
130
- this.metadata = info.metadata;
131
- this.transactions = info.transactions;
132
- return this;
133
- }
134
- fromString(str) {
135
- const buf = Buffer.from(str, 'hex');
136
- return this.fromBuffer(buf);
137
- }
138
- fromObject(obj) {
139
- const info = Block._fromObject(obj);
140
- this.header = info.header;
141
- this.metadata = info.metadata;
142
- this.transactions = info.transactions;
143
- return this;
144
- }
145
62
  toObject() {
146
63
  const transactions = this.transactions.map(tx => tx.toObject());
147
64
  return {
148
65
  id: this.id,
149
66
  hash: this.hash,
150
67
  header: this.header.toObject(),
151
- metadata: this.metadata,
152
- transactions: transactions,
68
+ transactions,
153
69
  };
154
70
  }
155
- toJSON = this.toObject;
71
+ toJSON() {
72
+ return this.toObject();
73
+ }
156
74
  toBuffer() {
157
75
  return this.toBufferWriter().concat();
158
76
  }
@@ -164,25 +82,21 @@ export class Block {
164
82
  bw = new BufferWriter();
165
83
  }
166
84
  bw.write(this.header.toBuffer());
167
- bw.writeUInt8(this.metadata);
85
+ bw.writeVarintNum(0);
168
86
  bw.writeVarintNum(this.transactions.length);
169
- for (let i = 0; i < this.transactions.length; i++) {
170
- this.transactions[i].toBufferWriter(bw);
87
+ for (const tx of this.transactions) {
88
+ tx.toBufferWriter(bw);
171
89
  }
172
90
  return bw;
173
91
  }
174
92
  getTransactionHashes() {
175
- const hashes = [];
176
93
  if (this.transactions.length === 0) {
177
- return [Block.Values.NULL_HASH];
94
+ return [Block.NULL_HASH];
178
95
  }
179
- for (let t = 0; t < this.transactions.length; t++) {
180
- const tx = this.transactions[t];
181
- const txid = tx._getTxid();
182
- const hash = tx._getHash();
183
- const buf = Buffer.concat([hash, txid]);
184
- const resultHash = Hash.sha256sha256(buf);
185
- hashes.push(resultHash);
96
+ const hashes = [];
97
+ for (const tx of this.transactions) {
98
+ const combined = Buffer.concat([tx.hashBuffer, tx.txidBuffer]);
99
+ hashes.push(Hash.sha256sha256(combined));
186
100
  }
187
101
  return hashes;
188
102
  }
@@ -191,12 +105,12 @@ export class Block {
191
105
  let j = 0;
192
106
  for (let size = tree.length; size > 1; size = Math.floor(size / 2)) {
193
107
  if (size % 2 === 1) {
194
- tree.push(Block.Values.NULL_HASH);
108
+ tree.push(Block.NULL_HASH);
195
109
  size += 1;
196
110
  }
197
111
  for (let i = 0; i < size; i += 2) {
198
- const buf = Buffer.concat([tree[j + i], tree[j + i + 1]]);
199
- tree.push(Hash.sha256sha256(buf));
112
+ const combined = Buffer.concat([tree[j + i], tree[j + i + 1]]);
113
+ tree.push(Hash.sha256sha256(combined));
200
114
  }
201
115
  j += size;
202
116
  }
@@ -207,16 +121,45 @@ export class Block {
207
121
  return tree[tree.length - 1];
208
122
  }
209
123
  validMerkleRoot() {
210
- const h = new BN(this.header.merkleRoot.toString('hex'), 'hex');
211
- const c = new BN(this.getMerkleRoot().toString('hex'), 'hex');
212
- if (!h.eq(c)) {
213
- return false;
214
- }
215
- return true;
124
+ const headerRoot = BN.fromBuffer(this.header.merkleRoot);
125
+ const computedRoot = BN.fromBuffer(this.getMerkleRoot());
126
+ return headerRoot.eq(computedRoot);
216
127
  }
217
- _getHash() {
218
- const header = this.header;
219
- return header._getHash();
128
+ toMerkleBlock(txids) {
129
+ if (!Array.isArray(txids) || txids.length === 0) {
130
+ throw new TypeError('txids must be a non-empty array of transaction IDs');
131
+ }
132
+ for (const txid of txids) {
133
+ if (!/^[0-9a-fA-F]{64}$/.test(txid)) {
134
+ throw new TypeError(`Invalid transaction ID format: ${txid}`);
135
+ }
136
+ }
137
+ if (this.transactions.length === 0) {
138
+ throw new Error('Cannot create MerkleBlock from block with no transactions');
139
+ }
140
+ const vHashes = [];
141
+ const vMatch = [];
142
+ for (const tx of this.transactions) {
143
+ const txhash = tx.hash;
144
+ const txid = tx.txid;
145
+ const txidLower = txid.toLowerCase();
146
+ vMatch.push(false);
147
+ vHashes.push(txhash);
148
+ const isMatch = txids.some(id => id.toLowerCase() === txidLower);
149
+ vMatch.push(isMatch);
150
+ vHashes.push(txid);
151
+ }
152
+ const nLeaves = vHashes.length;
153
+ const height = calcTreeHeight(nLeaves);
154
+ const vBits = [];
155
+ const vHash = [];
156
+ traverseAndBuild(height, 0, nLeaves, vHashes, vMatch, vBits, vHash, Block.NULL_HASH);
157
+ return new MerkleBlock({
158
+ header: this.header,
159
+ numTransactions: this.transactions.length,
160
+ hashes: vHash,
161
+ flags: vBits.map(b => (b ? 1 : 0)),
162
+ });
220
163
  }
221
164
  get hash() {
222
165
  if (!this._id) {
@@ -230,4 +173,59 @@ export class Block {
230
173
  inspect() {
231
174
  return '<Block ' + this.id + '>';
232
175
  }
176
+ static _from(arg) {
177
+ if (Buffer.isBuffer(arg)) {
178
+ return Block._readFromBuffer(new BufferReader(arg));
179
+ }
180
+ else if (typeof arg === 'object' && arg !== null) {
181
+ return Block._fromObject(arg);
182
+ }
183
+ throw new TypeError('Unrecognized argument for Block');
184
+ }
185
+ static _fromObject(data) {
186
+ const transactions = [];
187
+ if (data.transactions) {
188
+ for (const tx of data.transactions) {
189
+ transactions.push(tx instanceof Transaction ? tx : new Transaction(tx));
190
+ }
191
+ }
192
+ let header;
193
+ if (data.header instanceof BlockHeader) {
194
+ header = data.header;
195
+ }
196
+ else if (data.header) {
197
+ header = new BlockHeader(data.header);
198
+ }
199
+ else {
200
+ header = new BlockHeader();
201
+ }
202
+ return { header, transactions };
203
+ }
204
+ static _readFromBuffer(br) {
205
+ $.checkState(!br.finished(), 'No block data received');
206
+ const header = BlockHeader.fromBufferReader(br);
207
+ const metadataCount = br.readVarintNum();
208
+ for (let i = 0; i < metadataCount; i++) {
209
+ br.readUInt32LE();
210
+ const dataLength = br.readVarintNum();
211
+ br.read(dataLength);
212
+ }
213
+ const transactionCount = br.readVarintNum();
214
+ const transactions = [];
215
+ for (let i = 0; i < transactionCount; i++) {
216
+ const tx = new Transaction();
217
+ transactions.push(tx.fromBufferReader(br));
218
+ }
219
+ return { header, transactions };
220
+ }
221
+ _initEmpty() {
222
+ this.header = new BlockHeader();
223
+ this.transactions = [];
224
+ }
225
+ _fromString(str) {
226
+ const buf = Buffer.from(str, 'hex');
227
+ const info = Block._readFromBuffer(new BufferReader(buf));
228
+ this.header = info.header;
229
+ this.transactions = info.transactions;
230
+ }
233
231
  }