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,23 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Transaction = void 0;
4
- const preconditions_js_1 = require("../util/preconditions.js");
5
- const js_js_1 = require("../util/js.js");
6
- const bufferreader_js_1 = require("../encoding/bufferreader.js");
7
- const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
8
- const hash_js_1 = require("../crypto/hash.js");
9
- const signature_js_1 = require("../crypto/signature.js");
10
- const sighash_js_1 = require("./sighash.js");
11
- const errors_js_1 = require("../errors.js");
12
- const address_js_1 = require("../address.js");
13
- const unspentoutput_js_1 = require("./unspentoutput.js");
14
- const input_js_1 = require("./input.js");
15
- const output_js_1 = require("./output.js");
16
- const script_js_1 = require("../script.js");
17
- const privatekey_js_1 = require("../privatekey.js");
18
- const bn_js_1 = require("../crypto/bn.js");
19
- const sighash_js_2 = require("./sighash.js");
20
- const interpreter_js_1 = require("../script/interpreter.js");
4
+ const preconditions_1 = require("../util/preconditions");
5
+ const js_1 = require("../util/js");
6
+ const bufferreader_1 = require("../encoding/bufferreader");
7
+ const bufferwriter_1 = require("../encoding/bufferwriter");
8
+ const hash_1 = require("../crypto/hash");
9
+ const signature_1 = require("../crypto/signature");
10
+ const sighash_1 = require("./sighash");
11
+ const errors_1 = require("../errors");
12
+ const address_1 = require("../address");
13
+ const unspentoutput_1 = require("./unspentoutput");
14
+ const input_1 = require("./input");
15
+ const output_1 = require("./output");
16
+ const script_1 = require("../script");
17
+ const privatekey_1 = require("../privatekey");
18
+ const bn_1 = require("../crypto/bn");
19
+ const sighash_2 = require("./sighash");
20
+ const interpreter_1 = require("../script/interpreter");
21
+ const util_1 = require("../util");
21
22
  const CURRENT_VERSION = 2;
22
23
  const DEFAULT_NLOCKTIME = 0;
23
24
  const MAX_BLOCK_SIZE = 32_000_000;
@@ -29,7 +30,7 @@ const NLOCKTIME_MAX_VALUE = 4294967295;
29
30
  const FEE_PER_KB = 1_000;
30
31
  const CHANGE_OUTPUT_MAX_SIZE = 20 + 4 + 34 + 4;
31
32
  const MAXIMUM_EXTRA_SIZE = 4 + 9 + 9 + 4;
32
- const NULL_HASH = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
33
+ const NULL_HASH = util_1.BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
33
34
  class Transaction {
34
35
  static DUST_AMOUNT = DUST_AMOUNT;
35
36
  static FEE_SECURITY_MARGIN = FEE_SECURITY_MARGIN;
@@ -62,10 +63,10 @@ class Transaction {
62
63
  if (serialized instanceof Transaction) {
63
64
  return Transaction.shallowCopy(serialized);
64
65
  }
65
- else if (typeof serialized === 'string' && js_js_1.JSUtil.isHexa(serialized)) {
66
+ else if (typeof serialized === 'string' && js_1.JSUtil.isHexa(serialized)) {
66
67
  this.fromString(serialized);
67
68
  }
68
- else if (Buffer.isBuffer(serialized)) {
69
+ else if (util_1.BufferUtil.isBuffer(serialized)) {
69
70
  this.fromBuffer(serialized);
70
71
  }
71
72
  else if (serialized && typeof serialized === 'object') {
@@ -97,22 +98,28 @@ class Transaction {
97
98
  get hash() {
98
99
  if (!this._hash) {
99
100
  const hashBuffer = this._getHash();
100
- const reader = new bufferreader_js_1.BufferReader(hashBuffer);
101
+ const reader = new bufferreader_1.BufferReader(hashBuffer);
101
102
  this._hash = reader.readReverse(32).toString('hex');
102
103
  }
103
104
  return this._hash;
104
105
  }
106
+ get hashBuffer() {
107
+ return this._getHash();
108
+ }
105
109
  get id() {
106
110
  return this.txid;
107
111
  }
108
112
  get txid() {
109
113
  if (!this._txid) {
110
114
  const txidBuffer = this._getTxid();
111
- const reader = new bufferreader_js_1.BufferReader(txidBuffer);
115
+ const reader = new bufferreader_1.BufferReader(txidBuffer);
112
116
  this._txid = reader.readReverse(32).toString('hex');
113
117
  }
114
118
  return this._txid;
115
119
  }
120
+ get txidBuffer() {
121
+ return this._getTxid();
122
+ }
116
123
  get inputAmount() {
117
124
  return this._getInputAmount();
118
125
  }
@@ -138,10 +145,10 @@ class Transaction {
138
145
  this._version = version;
139
146
  }
140
147
  _getHash() {
141
- return hash_js_1.Hash.sha256sha256(this.toBuffer());
148
+ return hash_1.Hash.sha256sha256(this.toBuffer());
142
149
  }
143
150
  _getTxid() {
144
- const writer = new bufferwriter_js_1.BufferWriter();
151
+ const writer = new bufferwriter_1.BufferWriter();
145
152
  writer.writeInt32LE(this.version);
146
153
  const inputHashes = this._getTxInputHashes();
147
154
  const outputHashes = this._getTxOutputHashes();
@@ -152,7 +159,7 @@ class Transaction {
152
159
  writer.write(outputMerkleRootAndHeight.root);
153
160
  writer.writeUInt8(outputMerkleRootAndHeight.height);
154
161
  writer.writeUInt32LE(this.nLockTime);
155
- return hash_js_1.Hash.sha256sha256(writer.toBuffer());
162
+ return hash_1.Hash.sha256sha256(writer.toBuffer());
156
163
  }
157
164
  _getTxInputHashes() {
158
165
  const hashes = [];
@@ -161,11 +168,11 @@ class Transaction {
161
168
  }
162
169
  for (let i = 0; i < this.inputs.length; i++) {
163
170
  const input = this.inputs[i];
164
- const writer = new bufferwriter_js_1.BufferWriter();
171
+ const writer = new bufferwriter_1.BufferWriter();
165
172
  writer.writeReverse(input.prevTxId);
166
173
  writer.writeUInt32LE(input.outputIndex);
167
174
  writer.writeUInt32LE(Number(input.sequenceNumber));
168
- const hash = hash_js_1.Hash.sha256sha256(writer.toBuffer());
175
+ const hash = hash_1.Hash.sha256sha256(writer.toBuffer());
169
176
  hashes.push(hash);
170
177
  }
171
178
  return hashes;
@@ -177,10 +184,10 @@ class Transaction {
177
184
  }
178
185
  for (let i = 0; i < this.outputs.length; i++) {
179
186
  const output = this.outputs[i];
180
- const writer = new bufferwriter_js_1.BufferWriter();
181
- writer.writeUInt64LEBN(new bn_js_1.BN(output.satoshis));
187
+ const writer = new bufferwriter_1.BufferWriter();
188
+ writer.writeUInt64LEBN(new bn_1.BN(output.satoshis));
182
189
  writer.writeVarLengthBuffer(output.scriptBuffer);
183
- const hash = hash_js_1.Hash.sha256sha256(writer.toBuffer());
190
+ const hash = hash_1.Hash.sha256sha256(writer.toBuffer());
184
191
  hashes.push(hash);
185
192
  }
186
193
  return hashes;
@@ -201,8 +208,8 @@ class Transaction {
201
208
  size += 1;
202
209
  }
203
210
  for (let i = 0; i < size; i += 2) {
204
- const buf = Buffer.concat([hashes[j + i], hashes[j + i + 1]]);
205
- hashes.push(hash_js_1.Hash.sha256sha256(buf));
211
+ const buf = util_1.BufferUtil.concat([hashes[j + i], hashes[j + i + 1]]);
212
+ hashes.push(hash_1.Hash.sha256sha256(buf));
206
213
  }
207
214
  j += size;
208
215
  }
@@ -268,7 +275,7 @@ class Transaction {
268
275
  if (sigError)
269
276
  return sigError;
270
277
  if (this._hasInvalidSatoshis()) {
271
- return new errors_js_1.BitcoreError('Invalid satoshis in outputs');
278
+ return new errors_1.BitcoreError('Invalid satoshis in outputs');
272
279
  }
273
280
  return null;
274
281
  }
@@ -278,7 +285,7 @@ class Transaction {
278
285
  }
279
286
  for (const output of this.outputs) {
280
287
  if (output.satoshis < Transaction.DUST_AMOUNT && !output.isOpReturn()) {
281
- return new errors_js_1.BitcoreError('Dust outputs not allowed');
288
+ return new errors_1.BitcoreError('Dust outputs not allowed');
282
289
  }
283
290
  }
284
291
  return null;
@@ -288,7 +295,7 @@ class Transaction {
288
295
  return null;
289
296
  }
290
297
  if (!this.isFullySigned()) {
291
- return new errors_js_1.BitcoreError('Transaction is not fully signed');
298
+ return new errors_1.BitcoreError('Transaction is not fully signed');
292
299
  }
293
300
  return null;
294
301
  }
@@ -309,12 +316,12 @@ class Transaction {
309
316
  return true;
310
317
  }
311
318
  toBuffer() {
312
- const writer = new bufferwriter_js_1.BufferWriter();
319
+ const writer = new bufferwriter_1.BufferWriter();
313
320
  return this.toBufferWriter(writer).toBuffer();
314
321
  }
315
322
  toBufferWriter(writer) {
316
323
  if (!writer) {
317
- writer = new bufferwriter_js_1.BufferWriter();
324
+ writer = new bufferwriter_1.BufferWriter();
318
325
  }
319
326
  writer.writeInt32LE(this.version);
320
327
  writer.writeVarintNum(this.inputs.length);
@@ -323,34 +330,34 @@ class Transaction {
323
330
  }
324
331
  writer.writeVarintNum(this.outputs.length);
325
332
  for (const output of this.outputs) {
326
- writer.writeUInt64LEBN(new bn_js_1.BN(output.satoshis));
333
+ writer.writeUInt64LEBN(new bn_1.BN(output.satoshis));
327
334
  writer.writeVarLengthBuffer(output.scriptBuffer);
328
335
  }
329
336
  writer.writeUInt32LE(this.nLockTime);
330
337
  return writer;
331
338
  }
332
339
  fromBuffer(buffer) {
333
- const reader = new bufferreader_js_1.BufferReader(buffer);
340
+ const reader = new bufferreader_1.BufferReader(buffer);
334
341
  return this.fromBufferReader(reader);
335
342
  }
336
343
  fromBufferReader(reader) {
337
- preconditions_js_1.Preconditions.checkArgument(!reader.finished(), 'No transaction data received');
344
+ preconditions_1.Preconditions.checkArgument(!reader.finished(), 'No transaction data received');
338
345
  this.version = reader.readInt32LE();
339
346
  const sizeTxIns = reader.readVarintNum();
340
347
  for (let i = 0; i < sizeTxIns; i++) {
341
- const input = input_js_1.Input.fromBufferReader(reader);
348
+ const input = input_1.Input.fromBufferReader(reader);
342
349
  this.inputs.push(input);
343
350
  }
344
351
  const sizeTxOuts = reader.readVarintNum();
345
352
  for (let i = 0; i < sizeTxOuts; i++) {
346
- const output = output_js_1.Output.fromBufferReader(reader);
353
+ const output = output_1.Output.fromBufferReader(reader);
347
354
  this.outputs.push(output);
348
355
  }
349
356
  this.nLockTime = reader.readUInt32LE();
350
357
  return this;
351
358
  }
352
359
  fromString(str) {
353
- return this.fromBuffer(Buffer.from(str, 'hex'));
360
+ return this.fromBuffer(util_1.BufferUtil.from(str, 'hex'));
354
361
  }
355
362
  toObject() {
356
363
  const inputs = this.inputs.map(input => input.toObject());
@@ -377,7 +384,7 @@ class Transaction {
377
384
  }
378
385
  toJSON = this.toObject;
379
386
  fromObject(arg) {
380
- preconditions_js_1.Preconditions.checkArgument(typeof arg === 'object' && arg !== null, 'Must provide an object to deserialize a transaction');
387
+ preconditions_1.Preconditions.checkArgument(typeof arg === 'object' && arg !== null, 'Must provide an object to deserialize a transaction');
381
388
  let transaction;
382
389
  if (arg instanceof Transaction) {
383
390
  const obj = arg.toObject();
@@ -400,7 +407,7 @@ class Transaction {
400
407
  this.nLockTime = transaction.nLockTime || DEFAULT_NLOCKTIME;
401
408
  if (transaction.inputs) {
402
409
  for (const inputData of transaction.inputs) {
403
- const input = new input_js_1.Input({
410
+ const input = new input_1.Input({
404
411
  prevTxId: inputData.prevTxId,
405
412
  outputIndex: inputData.outputIndex,
406
413
  sequenceNumber: inputData.sequenceNumber,
@@ -413,7 +420,7 @@ class Transaction {
413
420
  }
414
421
  if (transaction.outputs) {
415
422
  for (const outputData of transaction.outputs) {
416
- const output = new output_js_1.Output({
423
+ const output = new output_1.Output({
417
424
  satoshis: outputData.satoshis,
418
425
  script: outputData.script,
419
426
  });
@@ -423,7 +430,7 @@ class Transaction {
423
430
  if (transaction.changeScript) {
424
431
  this._changeScript =
425
432
  typeof transaction.changeScript === 'string'
426
- ? script_js_1.Script.fromString(transaction.changeScript)
433
+ ? script_1.Script.fromString(transaction.changeScript)
427
434
  : transaction.changeScript;
428
435
  }
429
436
  if (transaction.changeIndex !== undefined) {
@@ -465,7 +472,7 @@ class Transaction {
465
472
  if (exists) {
466
473
  return this;
467
474
  }
468
- const utxo = utxos instanceof unspentoutput_js_1.UnspentOutput ? utxos : new unspentoutput_js_1.UnspentOutput(utxos);
475
+ const utxo = utxos instanceof unspentoutput_1.UnspentOutput ? utxos : new unspentoutput_1.UnspentOutput(utxos);
469
476
  if (pubkeys && threshold) {
470
477
  this._fromMultisigUtxo(utxo, pubkeys, threshold, opts);
471
478
  }
@@ -475,7 +482,7 @@ class Transaction {
475
482
  return this;
476
483
  }
477
484
  change(address) {
478
- this._changeScript = script_js_1.Script.fromAddress(address);
485
+ this._changeScript = script_1.Script.fromAddress(address);
479
486
  this._updateChangeOutput();
480
487
  return this;
481
488
  }
@@ -486,9 +493,9 @@ class Transaction {
486
493
  }
487
494
  return this;
488
495
  }
489
- preconditions_js_1.Preconditions.checkArgument(js_js_1.JSUtil.isNaturalNumber(amount), 'Amount is expected to be a positive integer');
490
- this.addOutput(new output_js_1.Output({
491
- script: script_js_1.Script.fromAddress(new address_js_1.Address(address)),
496
+ preconditions_1.Preconditions.checkArgument(js_1.JSUtil.isNaturalNumber(amount), 'Amount is expected to be a positive integer');
497
+ this.addOutput(new output_1.Output({
498
+ script: script_1.Script.fromAddress(new address_1.Address(address)),
492
499
  satoshis: amount,
493
500
  }));
494
501
  return this;
@@ -504,34 +511,34 @@ class Transaction {
504
511
  return this;
505
512
  }
506
513
  signSchnorr(privateKey) {
507
- return this.sign(privateKey, signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_LOTUS, 'schnorr');
514
+ return this.sign(privateKey, signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS, 'schnorr');
508
515
  }
509
516
  getMuSig2Inputs() {
510
- return this.inputs.filter(input => input instanceof input_js_1.MuSigTaprootInput);
517
+ return this.inputs.filter(input => input instanceof input_1.MuSig2TaprootInput);
511
518
  }
512
519
  getMuSig2Sighash(inputIndex) {
513
520
  const input = this.inputs[inputIndex];
514
- if (!(input instanceof input_js_1.MuSigTaprootInput)) {
515
- throw new Error(`Input ${inputIndex} is not a MuSigTaprootInput`);
521
+ if (!(input instanceof input_1.MuSig2TaprootInput)) {
522
+ throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
516
523
  }
517
524
  if (!input.output) {
518
525
  throw new Error(`Input ${inputIndex} is missing output information`);
519
526
  }
520
- const sigtype = signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_LOTUS;
521
- return (0, sighash_js_2.sighash)(this, sigtype, inputIndex, input.output.script, new bn_js_1.BN(input.output.satoshis));
527
+ const sigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS;
528
+ return (0, sighash_2.sighash)(this, sigtype, inputIndex, input.output.script, new bn_1.BN(input.output.satoshis));
522
529
  }
523
530
  addMuSig2Nonce(inputIndex, signerIndex, nonce) {
524
531
  const input = this.inputs[inputIndex];
525
- if (!(input instanceof input_js_1.MuSigTaprootInput)) {
526
- throw new Error(`Input ${inputIndex} is not a MuSigTaprootInput`);
532
+ if (!(input instanceof input_1.MuSig2TaprootInput)) {
533
+ throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
527
534
  }
528
535
  input.addPublicNonce(signerIndex, nonce);
529
536
  return this;
530
537
  }
531
538
  addMuSig2PartialSignature(inputIndex, signerIndex, partialSig) {
532
539
  const input = this.inputs[inputIndex];
533
- if (!(input instanceof input_js_1.MuSigTaprootInput)) {
534
- throw new Error(`Input ${inputIndex} is not a MuSigTaprootInput`);
540
+ if (!(input instanceof input_1.MuSig2TaprootInput)) {
541
+ throw new Error(`Input ${inputIndex} is not a MuSig2TaprootInput`);
535
542
  }
536
543
  input.addPartialSignature(signerIndex, partialSig);
537
544
  return this;
@@ -540,36 +547,36 @@ class Transaction {
540
547
  const musigInputs = this.getMuSig2Inputs();
541
548
  for (let i = 0; i < this.inputs.length; i++) {
542
549
  const input = this.inputs[i];
543
- if (input instanceof input_js_1.MuSigTaprootInput) {
550
+ if (input instanceof input_1.MuSig2TaprootInput) {
544
551
  if (!input.hasAllPartialSignatures()) {
545
552
  throw new Error(`MuSig2 input ${i} is missing partial signatures. ` +
546
553
  `Has ${input.partialSignatures?.size || 0} of ${input.keyAggContext?.pubkeys.length || 0}`);
547
554
  }
548
555
  const sighash = this.getMuSig2Sighash(i);
549
- input.finalizeMuSigSignature(this, sighash);
556
+ input.finalizeMuSig2Signature(this, sighash);
550
557
  }
551
558
  }
552
559
  return this;
553
560
  }
554
561
  getSignatures(privKey, sigtype, signingMethod) {
555
- const privateKey = new privatekey_js_1.PrivateKey(privKey);
562
+ const privateKey = new privatekey_1.PrivateKey(privKey);
556
563
  const results = [];
557
- const hashData = hash_js_1.Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
564
+ const hashData = hash_1.Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
558
565
  for (let index = 0; index < this.inputs.length; index++) {
559
566
  const input = this.inputs[index];
560
567
  let inputSigtype = sigtype;
561
568
  if (!inputSigtype) {
562
- if (input.output?.script.isPayToTaproot()) {
569
+ if (input.output?.script.isTaprootOut()) {
563
570
  const taprootInput = input;
564
571
  if (taprootInput.hasScriptTree()) {
565
- inputSigtype = signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_FORKID;
572
+ inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
566
573
  }
567
574
  else {
568
- inputSigtype = signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_LOTUS;
575
+ inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_LOTUS;
569
576
  }
570
577
  }
571
578
  else {
572
- inputSigtype = signature_js_1.Signature.SIGHASH_ALL | signature_js_1.Signature.SIGHASH_FORKID;
579
+ inputSigtype = signature_1.Signature.SIGHASH_ALL | signature_1.Signature.SIGHASH_FORKID;
573
580
  }
574
581
  }
575
582
  const signatures = input.getSignatures(this, privateKey, index, inputSigtype, hashData, signingMethod);
@@ -588,10 +595,10 @@ class Transaction {
588
595
  return input.isValidSignature(this, sig);
589
596
  }
590
597
  verifySignature(sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod) {
591
- return (0, sighash_js_1.verify)(this, sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod);
598
+ return (0, sighash_1.verify)(this, sig, pubkey, nin, subscript, satoshisBN, flags, signingMethod);
592
599
  }
593
600
  lockUntilDate(time) {
594
- preconditions_js_1.Preconditions.checkArgument(!!time, 'time is required');
601
+ preconditions_1.Preconditions.checkArgument(!!time, 'time is required');
595
602
  if (typeof time === 'number' &&
596
603
  time < Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) {
597
604
  throw new Error('Lock time too early');
@@ -600,15 +607,15 @@ class Transaction {
600
607
  time = time.getTime() / 1000;
601
608
  }
602
609
  for (let i = 0; i < this.inputs.length; i++) {
603
- if (this.inputs[i].sequenceNumber === input_js_1.Input.DEFAULT_SEQNUMBER) {
604
- this.inputs[i].sequenceNumber = input_js_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
610
+ if (this.inputs[i].sequenceNumber === input_1.Input.DEFAULT_SEQNUMBER) {
611
+ this.inputs[i].sequenceNumber = input_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
605
612
  }
606
613
  }
607
614
  this.nLockTime = time;
608
615
  return this;
609
616
  }
610
617
  lockUntilBlockHeight(height) {
611
- preconditions_js_1.Preconditions.checkArgument(typeof height === 'number', 'height must be a number');
618
+ preconditions_1.Preconditions.checkArgument(typeof height === 'number', 'height must be a number');
612
619
  if (height >= Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT) {
613
620
  throw new Error('Block height too high');
614
621
  }
@@ -616,8 +623,8 @@ class Transaction {
616
623
  throw new Error('NLockTime out of range');
617
624
  }
618
625
  for (let i = 0; i < this.inputs.length; i++) {
619
- if (this.inputs[i].sequenceNumber === input_js_1.Input.DEFAULT_SEQNUMBER) {
620
- this.inputs[i].sequenceNumber = input_js_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
626
+ if (this.inputs[i].sequenceNumber === input_1.Input.DEFAULT_SEQNUMBER) {
627
+ this.inputs[i].sequenceNumber = input_1.Input.DEFAULT_LOCKTIME_SEQNUMBER;
621
628
  }
622
629
  }
623
630
  this.nLockTime = height;
@@ -636,8 +643,8 @@ class Transaction {
636
643
  return this.inputs.every(input => !!input.output);
637
644
  }
638
645
  addData(value) {
639
- this.addOutput(new output_js_1.Output({
640
- script: script_js_1.Script.buildDataOut(value),
646
+ this.addOutput(new output_1.Output({
647
+ script: script_1.Script.buildDataOut(value),
641
648
  satoshis: 0,
642
649
  }));
643
650
  return this;
@@ -663,7 +670,7 @@ class Transaction {
663
670
  x.i = i++;
664
671
  });
665
672
  copy.sort((first, second) => {
666
- const prevTxIdCompare = Buffer.compare(first.prevTxId, second.prevTxId);
673
+ const prevTxIdCompare = util_1.BufferUtil.compare(first.prevTxId, second.prevTxId);
667
674
  if (prevTxIdCompare !== 0)
668
675
  return prevTxIdCompare;
669
676
  const outputIndexCompare = first.outputIndex - second.outputIndex;
@@ -685,7 +692,7 @@ class Transaction {
685
692
  const satoshisCompare = first.satoshis - second.satoshis;
686
693
  if (satoshisCompare !== 0)
687
694
  return satoshisCompare;
688
- const scriptCompare = Buffer.compare(first.scriptBuffer, second.scriptBuffer);
695
+ const scriptCompare = util_1.BufferUtil.compare(first.scriptBuffer, second.scriptBuffer);
689
696
  if (scriptCompare !== 0)
690
697
  return scriptCompare;
691
698
  return (first.i -
@@ -820,14 +827,11 @@ class Transaction {
820
827
  try {
821
828
  const verifyFlags = flags !== undefined
822
829
  ? flags
823
- : interpreter_js_1.Interpreter.SCRIPT_VERIFY_P2SH |
824
- interpreter_js_1.Interpreter.SCRIPT_VERIFY_STRICTENC |
825
- interpreter_js_1.Interpreter.SCRIPT_VERIFY_DERSIG |
826
- interpreter_js_1.Interpreter.SCRIPT_VERIFY_LOW_S |
827
- interpreter_js_1.Interpreter.SCRIPT_VERIFY_NULLFAIL |
828
- interpreter_js_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
829
- interpreter_js_1.Interpreter.SCRIPT_ENABLE_SCHNORR_MULTISIG;
830
- const interpreter = new interpreter_js_1.Interpreter();
830
+ : interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
831
+ interpreter_1.Interpreter.SCRIPT_VERIFY_CLEANSTACK |
832
+ interpreter_1.Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
833
+ interpreter_1.Interpreter.SCRIPT_VERIFY_INPUT_SIGCHECKS;
834
+ const interpreter = new interpreter_1.Interpreter();
831
835
  const isValid = interpreter.verify(input.script, input.output.script, this, i, verifyFlags, BigInt(input.output.satoshis));
832
836
  if (!isValid) {
833
837
  return {
@@ -851,7 +855,7 @@ class Transaction {
851
855
  this.inputs[0].outputIndex === 0xffffffff);
852
856
  }
853
857
  uncheckedAddInput(input) {
854
- preconditions_js_1.Preconditions.checkArgument(input instanceof input_js_1.Input, 'input must be an Input');
858
+ preconditions_1.Preconditions.checkArgument(input instanceof input_1.Input, 'input must be an Input');
855
859
  this.inputs.push(input);
856
860
  this._inputAmount = undefined;
857
861
  this._updateChangeOutput();
@@ -861,7 +865,7 @@ class Transaction {
861
865
  const isInvalidSorting = this.outputs.length !== newOutputs.length ||
862
866
  this.outputs.some((output, index) => output !== newOutputs[index]);
863
867
  if (isInvalidSorting) {
864
- throw new errors_js_1.BitcoreError('Invalid sorting: outputs must contain the same elements');
868
+ throw new errors_1.BitcoreError('Invalid sorting: outputs must contain the same elements');
865
869
  }
866
870
  if (this._changeIndex !== undefined) {
867
871
  const changeOutput = this.outputs[this._changeIndex];
@@ -872,82 +876,90 @@ class Transaction {
872
876
  }
873
877
  _fromNonP2SH(utxo) {
874
878
  let clazz;
875
- const unspentOutput = new unspentoutput_js_1.UnspentOutput(utxo);
876
- if (unspentOutput.script.isPayToTaproot()) {
879
+ const unspentOutput = new unspentoutput_1.UnspentOutput(utxo);
880
+ if (unspentOutput.script.isTaprootOut()) {
877
881
  if (unspentOutput.keyAggContext &&
878
882
  unspentOutput.mySignerIndex !== undefined) {
879
- clazz = input_js_1.MuSigTaprootInput;
880
- const input = new input_js_1.MuSigTaprootInput({
881
- output: new output_js_1.Output({
883
+ if (!unspentOutput.internalPubKey || !unspentOutput.merkleRoot) {
884
+ throw new errors_1.BitcoreError('MuSig2 Taproot input requires internalPubKey and merkleRoot');
885
+ }
886
+ clazz = input_1.MuSig2TaprootInput;
887
+ const input = new input_1.MuSig2TaprootInput({
888
+ output: new output_1.Output({
882
889
  script: unspentOutput.script,
883
890
  satoshis: unspentOutput.satoshis,
884
891
  }),
885
892
  prevTxId: unspentOutput.txId,
886
893
  outputIndex: unspentOutput.outputIndex,
887
- script: new script_js_1.Script(),
894
+ script: new script_1.Script(),
888
895
  keyAggContext: unspentOutput.keyAggContext,
889
896
  mySignerIndex: unspentOutput.mySignerIndex,
897
+ internalPubKey: unspentOutput.internalPubKey,
898
+ merkleRoot: unspentOutput.merkleRoot,
890
899
  });
891
900
  this.addInput(input);
892
901
  return;
893
902
  }
894
- clazz = input_js_1.TaprootInput;
895
- const taprootInput = new input_js_1.TaprootInput({
896
- output: new output_js_1.Output({
903
+ if (!unspentOutput.internalPubKey) {
904
+ throw new errors_1.BitcoreError('Taproot input requires internalPubKey');
905
+ }
906
+ clazz = input_1.TaprootInput;
907
+ const taprootInput = new input_1.TaprootInput({
908
+ output: new output_1.Output({
897
909
  script: unspentOutput.script,
898
910
  satoshis: unspentOutput.satoshis,
899
911
  }),
900
912
  prevTxId: unspentOutput.txId,
901
913
  outputIndex: unspentOutput.outputIndex,
902
- script: new script_js_1.Script(),
914
+ script: new script_1.Script(),
903
915
  internalPubKey: unspentOutput.internalPubKey,
904
- merkleRoot: unspentOutput.merkleRoot || Buffer.alloc(32),
916
+ merkleRoot: unspentOutput.merkleRoot || util_1.BufferUtil.alloc(32),
905
917
  });
906
918
  this.addInput(taprootInput);
907
919
  return;
908
920
  }
909
- else if (unspentOutput.script.isPayToPublicKeyHash()) {
910
- clazz = input_js_1.PublicKeyHashInput;
921
+ else if (unspentOutput.script.isPublicKeyHashOut()) {
922
+ clazz = input_1.PublicKeyHashInput;
911
923
  }
912
924
  else if (unspentOutput.script.isPublicKeyOut()) {
913
- clazz = input_js_1.PublicKeyInput;
925
+ clazz = input_1.PublicKeyInput;
914
926
  }
915
927
  else {
916
- clazz = input_js_1.Input;
928
+ clazz = input_1.Input;
917
929
  }
918
930
  this.addInput(new clazz({
919
- output: new output_js_1.Output({
931
+ output: new output_1.Output({
920
932
  script: unspentOutput.script,
921
933
  satoshis: unspentOutput.satoshis,
922
934
  }),
923
935
  prevTxId: unspentOutput.txId,
924
936
  outputIndex: unspentOutput.outputIndex,
925
- script: new script_js_1.Script(),
937
+ script: new script_1.Script(),
926
938
  }));
927
939
  }
928
940
  _fromMultisigUtxo(utxo, pubkeys, threshold, opts) {
929
- preconditions_js_1.Preconditions.checkArgument(threshold <= pubkeys.length, 'Number of required signatures must be greater than the number of public keys');
930
- const unspentOutput = new unspentoutput_js_1.UnspentOutput(utxo);
941
+ preconditions_1.Preconditions.checkArgument(threshold <= pubkeys.length, 'Number of required signatures must be greater than the number of public keys');
942
+ const unspentOutput = new unspentoutput_1.UnspentOutput(utxo);
931
943
  if (unspentOutput.script.isMultisigOut()) {
932
- this.addInput(new input_js_1.MultisigInput(new input_js_1.Input({
933
- output: new output_js_1.Output({
944
+ this.addInput(new input_1.MultisigInput(new input_1.Input({
945
+ output: new output_1.Output({
934
946
  script: unspentOutput.script,
935
947
  satoshis: unspentOutput.satoshis,
936
948
  }),
937
949
  prevTxId: unspentOutput.txId,
938
950
  outputIndex: unspentOutput.outputIndex,
939
- script: new script_js_1.Script(),
951
+ script: new script_1.Script(),
940
952
  }), pubkeys, threshold, undefined, opts));
941
953
  }
942
- else if (unspentOutput.script.isPayToScriptHash()) {
943
- this.addInput(new input_js_1.MultisigScriptHashInput(new input_js_1.Input({
944
- output: new output_js_1.Output({
954
+ else if (unspentOutput.script.isScriptHashOut()) {
955
+ this.addInput(new input_1.MultisigScriptHashInput(new input_1.Input({
956
+ output: new output_1.Output({
945
957
  script: unspentOutput.script,
946
958
  satoshis: unspentOutput.satoshis,
947
959
  }),
948
960
  prevTxId: unspentOutput.txId,
949
961
  outputIndex: unspentOutput.outputIndex,
950
- script: new script_js_1.Script(),
962
+ script: new script_1.Script(),
951
963
  }), pubkeys, threshold, undefined, opts));
952
964
  }
953
965
  else {
@@ -967,7 +979,7 @@ class Transaction {
967
979
  const changeAmount = available - fee;
968
980
  if (changeAmount >= Transaction.DUST_AMOUNT) {
969
981
  this._changeIndex = this.outputs.length;
970
- this._addOutput(new output_js_1.Output({
982
+ this._addOutput(new output_1.Output({
971
983
  script: this._changeScript,
972
984
  satoshis: changeAmount,
973
985
  }));