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
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OutPoint = exports.OUTPOINT_SIZE = void 0;
4
+ const bufferreader_js_1 = require("../encoding/bufferreader.js");
5
+ const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
6
+ const buffer_js_1 = require("../util/buffer.js");
7
+ exports.OUTPOINT_SIZE = 36;
8
+ class OutPoint {
9
+ static NULL_INDEX = 0xffffffff;
10
+ _txid;
11
+ _n;
12
+ constructor(txid, n) {
13
+ if (txid === undefined) {
14
+ this._txid = buffer_js_1.BufferUtil.alloc(32, 0);
15
+ this._n = OutPoint.NULL_INDEX;
16
+ }
17
+ else if (buffer_js_1.BufferUtil.isBuffer(txid)) {
18
+ if (txid.length !== 32) {
19
+ throw new TypeError(`OutPoint txid buffer must be 32 bytes, got ${txid.length}`);
20
+ }
21
+ this._txid = buffer_js_1.BufferUtil.from(txid);
22
+ this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
23
+ }
24
+ else if (typeof txid === 'string') {
25
+ if (txid.length !== 64) {
26
+ throw new TypeError(`OutPoint txid hex string must be 64 characters, got ${txid.length}`);
27
+ }
28
+ this._txid = buffer_js_1.BufferUtil.reverse(buffer_js_1.BufferUtil.from(txid, 'hex'));
29
+ this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
30
+ }
31
+ else {
32
+ throw new TypeError('OutPoint txid must be a Buffer or hex string');
33
+ }
34
+ }
35
+ static fromObject(data) {
36
+ return new OutPoint(data.txid, data.outputIndex);
37
+ }
38
+ static fromBuffer(buf) {
39
+ const reader = new bufferreader_js_1.BufferReader(buf);
40
+ return OutPoint.fromBufferReader(reader);
41
+ }
42
+ static fromBufferReader(reader) {
43
+ const txidBuf = reader.read(32);
44
+ const n = reader.readUInt32LE();
45
+ const outpoint = new OutPoint();
46
+ outpoint._txid = txidBuf;
47
+ outpoint._n = n;
48
+ return outpoint;
49
+ }
50
+ isNull() {
51
+ return (this._n === OutPoint.NULL_INDEX && this._txid.every(byte => byte === 0));
52
+ }
53
+ getTxId() {
54
+ return buffer_js_1.BufferUtil.reverse(this._txid).toString('hex');
55
+ }
56
+ getTxIdBuffer() {
57
+ return buffer_js_1.BufferUtil.from(this._txid);
58
+ }
59
+ getN() {
60
+ return this._n;
61
+ }
62
+ toBuffer() {
63
+ const writer = new bufferwriter_js_1.BufferWriter();
64
+ this.toBufferWriter(writer);
65
+ return writer.toBuffer();
66
+ }
67
+ toBufferWriter(writer) {
68
+ writer.write(this._txid);
69
+ writer.writeUInt32LE(this._n);
70
+ return writer;
71
+ }
72
+ toObject() {
73
+ return {
74
+ txid: this.getTxId(),
75
+ outputIndex: this._n,
76
+ };
77
+ }
78
+ toString() {
79
+ return `COutPoint(${this.getTxId().substring(0, 10)}, ${this._n})`;
80
+ }
81
+ equals(other) {
82
+ return this._txid.equals(other._txid) && this._n === other._n;
83
+ }
84
+ lessThan(other) {
85
+ const cmp = this._txid.compare(other._txid);
86
+ return cmp < 0 || (cmp === 0 && this._n < other._n);
87
+ }
88
+ }
89
+ exports.OutPoint = OutPoint;
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Output = void 0;
4
+ const bn_js_1 = require("../crypto/bn.js");
4
5
  const preconditions_js_1 = require("../util/preconditions.js");
5
6
  const errors_js_1 = require("../errors.js");
6
7
  const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
8
+ const buffer_js_1 = require("../util/buffer.js");
7
9
  const js_js_1 = require("../util/js.js");
8
10
  const script_js_1 = require("../script.js");
9
- const bn_js_1 = require("../crypto/bn.js");
11
+ const opcode_js_1 = require("../opcode.js");
10
12
  const MAX_SAFE_INTEGER = 0x1fffffffffffff;
11
13
  class Output {
12
14
  satoshis;
@@ -22,7 +24,7 @@ class Output {
22
24
  this.satoshis = 0;
23
25
  this._satoshisBN = new bn_js_1.BN(0);
24
26
  }
25
- if (Buffer.isBuffer(args.script)) {
27
+ if (buffer_js_1.BufferUtil.isBuffer(args.script)) {
26
28
  this._scriptBuffer = args.script;
27
29
  }
28
30
  else if (args.scriptBuffer !== undefined) {
@@ -32,7 +34,7 @@ class Output {
32
34
  this.setScript(args.script);
33
35
  }
34
36
  else {
35
- this._scriptBuffer = Buffer.alloc(0);
37
+ this._scriptBuffer = buffer_js_1.BufferUtil.alloc(0);
36
38
  }
37
39
  }
38
40
  else {
@@ -111,7 +113,7 @@ class Output {
111
113
  this._scriptBuffer = this._script.toBuffer();
112
114
  this._script._isOutput = true;
113
115
  }
114
- else if (Buffer.isBuffer(script)) {
116
+ else if (buffer_js_1.BufferUtil.isBuffer(script)) {
115
117
  this.setScriptFromBuffer(script);
116
118
  }
117
119
  else {
@@ -153,7 +155,7 @@ class Output {
153
155
  }
154
156
  return !!(this._script &&
155
157
  this._script.chunks.length > 0 &&
156
- this._script.chunks[0].opcodenum === 0x6a);
158
+ this._script.chunks[0].opcodenum === opcode_js_1.Opcode.OP_RETURN);
157
159
  }
158
160
  toObject() {
159
161
  return {
@@ -181,7 +183,7 @@ class Output {
181
183
  obj.script = br.read(size);
182
184
  }
183
185
  else {
184
- obj.script = Buffer.from([]);
186
+ obj.script = buffer_js_1.BufferUtil.from([]);
185
187
  }
186
188
  return new Output(obj);
187
189
  }
@@ -217,10 +219,13 @@ class Output {
217
219
  return new Output(data);
218
220
  }
219
221
  isPayToPublicKeyHash() {
220
- return this.script.isPayToPublicKeyHash();
222
+ return this.script.isPublicKeyHashOut();
221
223
  }
222
224
  isPayToScriptHash() {
223
- return this.script.isPayToScriptHash();
225
+ return this.script.isScriptHashOut();
226
+ }
227
+ isPayToTaproot() {
228
+ return this.script.isTaprootOut();
224
229
  }
225
230
  getAddress() {
226
231
  try {
@@ -4,26 +4,26 @@ exports.BITS_64_ON = exports.SIGHASH_SINGLE_BUG = exports.DEFAULT_SIGN_FLAGS = v
4
4
  exports.sighash = sighash;
5
5
  exports.sign = sign;
6
6
  exports.verify = verify;
7
- const signature_js_1 = require("../crypto/signature.js");
8
- const script_js_1 = require("../script.js");
9
- const output_js_1 = require("./output.js");
10
- const bufferreader_js_1 = require("../encoding/bufferreader.js");
11
- const bufferwriter_js_1 = require("../encoding/bufferwriter.js");
12
- const bn_js_1 = require("../crypto/bn.js");
13
- const hash_js_1 = require("../crypto/hash.js");
14
- const ecdsa_js_1 = require("../crypto/ecdsa.js");
15
- const schnorr_js_1 = require("../crypto/schnorr.js");
16
- const preconditions_js_1 = require("../util/preconditions.js");
17
- const buffer_js_1 = require("../util/buffer.js");
18
- const interpreter_js_1 = require("../script/interpreter.js");
19
- const transaction_js_1 = require("./transaction.js");
20
- const input_js_1 = require("./input.js");
7
+ const signature_1 = require("../crypto/signature");
8
+ const script_1 = require("../script");
9
+ const output_1 = require("./output");
10
+ const bufferreader_1 = require("../encoding/bufferreader");
11
+ const bufferwriter_1 = require("../encoding/bufferwriter");
12
+ const bn_1 = require("../crypto/bn");
13
+ const hash_1 = require("../crypto/hash");
14
+ const ecdsa_1 = require("../crypto/ecdsa");
15
+ const schnorr_1 = require("../crypto/schnorr");
16
+ const preconditions_1 = require("../util/preconditions");
17
+ const buffer_1 = require("../util/buffer");
18
+ const interpreter_1 = require("../script/interpreter");
19
+ const transaction_1 = require("./transaction");
20
+ const input_1 = require("./input");
21
21
  const SIGHASH_SINGLE_BUG_CONST = '0000000000000000000000000000000000000000000000000000000000000001';
22
22
  const BITS_64_ON_CONST = 'ffffffffffffffff';
23
- const NULL_HASH = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
24
- const SIGHASH_ALGORITHM_MASK = 0x60;
23
+ const NULL_HASH = buffer_1.BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
24
+ const SIGHASH_ALGORITHM_MASK = signature_1.Signature.SIGHASH_ALGORITHM_MASK;
25
25
  const DEFAULT_SIGN_FLAGS_CONST = 1 << 16;
26
- function GetForkId() {
26
+ function getForkId() {
27
27
  return 0;
28
28
  }
29
29
  function getMerkleRoot(hashes) {
@@ -38,8 +38,8 @@ function getMerkleRoot(hashes) {
38
38
  for (let i = 0; i < currentHashes.length; i += 2) {
39
39
  const left = currentHashes[i];
40
40
  const right = i + 1 < currentHashes.length ? currentHashes[i + 1] : NULL_HASH;
41
- const combined = Buffer.concat([left, right]);
42
- const pairHash = hash_js_1.Hash.sha256sha256(combined);
41
+ const combined = buffer_1.BufferUtil.concat([left, right]);
42
+ const pairHash = hash_1.Hash.sha256sha256(combined);
43
43
  newHashes.push(pairHash);
44
44
  }
45
45
  currentHashes = newHashes;
@@ -47,107 +47,107 @@ function getMerkleRoot(hashes) {
47
47
  return { root: currentHashes[0], height };
48
48
  }
49
49
  function sighashForLotus(transaction, sighashType, inputNumber, spentOutputs, executedScriptHash, codeseparatorPos = 0xffffffff) {
50
- preconditions_js_1.Preconditions.checkArgument(spentOutputs.length === transaction.inputs.length, 'Must provide spent output for each input');
51
- preconditions_js_1.Preconditions.checkArgument(inputNumber < transaction.inputs.length, 'Input index out of range');
50
+ preconditions_1.Preconditions.checkArgument(spentOutputs.length === transaction.inputs.length, 'Must provide spent output for each input');
51
+ preconditions_1.Preconditions.checkArgument(inputNumber < transaction.inputs.length, 'Input index out of range');
52
52
  const baseType = sighashType & 0x03;
53
53
  const unusedBits = sighashType & 0x1c;
54
54
  if (baseType === 0 || unusedBits !== 0) {
55
55
  throw new Error('Invalid sighash type for SIGHASH_LOTUS');
56
56
  }
57
57
  const input = transaction.inputs[inputNumber];
58
- const writer = new bufferwriter_js_1.BufferWriter();
58
+ const writer = new bufferwriter_1.BufferWriter();
59
59
  writer.writeUInt32LE(sighashType >>> 0);
60
60
  const spendType = executedScriptHash ? 2 : 0;
61
- const inputHashWriter = new bufferwriter_js_1.BufferWriter();
61
+ const inputHashWriter = new bufferwriter_1.BufferWriter();
62
62
  inputHashWriter.writeUInt8(spendType);
63
63
  inputHashWriter.writeReverse(input.prevTxId);
64
64
  inputHashWriter.writeUInt32LE(input.outputIndex);
65
65
  inputHashWriter.writeUInt32LE(input.sequenceNumber);
66
66
  const spentOutput = spentOutputs[inputNumber];
67
- inputHashWriter.writeUInt64LEBN(new bn_js_1.BN(spentOutput.satoshis));
67
+ inputHashWriter.writeUInt64LEBN(new bn_1.BN(spentOutput.satoshis));
68
68
  inputHashWriter.writeVarLengthBuffer(spentOutput.scriptBuffer);
69
- const inputHash = hash_js_1.Hash.sha256sha256(inputHashWriter.toBuffer());
69
+ const inputHash = hash_1.Hash.sha256sha256(inputHashWriter.toBuffer());
70
70
  writer.write(inputHash);
71
71
  if (executedScriptHash) {
72
- preconditions_js_1.Preconditions.checkArgument(executedScriptHash.length === 32, 'executed_script_hash must be 32 bytes');
72
+ preconditions_1.Preconditions.checkArgument(executedScriptHash.length === 32, 'executed_script_hash must be 32 bytes');
73
73
  writer.writeUInt32LE(codeseparatorPos);
74
74
  writer.write(executedScriptHash);
75
75
  }
76
- if (!(sighashType & signature_js_1.Signature.SIGHASH_ANYONECANPAY)) {
76
+ if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
77
77
  writer.writeUInt32LE(inputNumber);
78
78
  const spentOutputHashes = spentOutputs.map(output => {
79
- const w = new bufferwriter_js_1.BufferWriter();
80
- w.writeUInt64LEBN(new bn_js_1.BN(output.satoshis));
79
+ const w = new bufferwriter_1.BufferWriter();
80
+ w.writeUInt64LEBN(new bn_1.BN(output.satoshis));
81
81
  w.writeVarLengthBuffer(output.scriptBuffer);
82
- return hash_js_1.Hash.sha256sha256(w.toBuffer());
82
+ return hash_1.Hash.sha256sha256(w.toBuffer());
83
83
  });
84
84
  const spentOutputsMerkle = getMerkleRoot(spentOutputHashes);
85
85
  writer.write(spentOutputsMerkle.root);
86
86
  const totalInputAmount = spentOutputs.reduce((sum, output) => sum + output.satoshis, 0);
87
- writer.writeUInt64LEBN(new bn_js_1.BN(totalInputAmount));
87
+ writer.writeUInt64LEBN(new bn_1.BN(totalInputAmount));
88
88
  }
89
- if (baseType === signature_js_1.Signature.SIGHASH_ALL) {
89
+ if (baseType === signature_1.Signature.SIGHASH_ALL) {
90
90
  const totalOutputAmount = transaction.outputs.reduce((sum, output) => sum + output.satoshis, 0);
91
- writer.writeUInt64LEBN(new bn_js_1.BN(totalOutputAmount));
91
+ writer.writeUInt64LEBN(new bn_1.BN(totalOutputAmount));
92
92
  }
93
93
  writer.writeUInt32LE(transaction.version || 2);
94
- if (!(sighashType & signature_js_1.Signature.SIGHASH_ANYONECANPAY)) {
94
+ if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
95
95
  const inputHashes = transaction.inputs.map(inp => {
96
- const w = new bufferwriter_js_1.BufferWriter();
96
+ const w = new bufferwriter_1.BufferWriter();
97
97
  w.writeReverse(inp.prevTxId);
98
98
  w.writeUInt32LE(inp.outputIndex);
99
99
  w.writeUInt32LE(inp.sequenceNumber);
100
- return hash_js_1.Hash.sha256sha256(w.toBuffer());
100
+ return hash_1.Hash.sha256sha256(w.toBuffer());
101
101
  });
102
102
  const inputsMerkle = getMerkleRoot(inputHashes);
103
103
  writer.write(inputsMerkle.root);
104
104
  writer.writeUInt8(inputsMerkle.height);
105
105
  }
106
- if (baseType === signature_js_1.Signature.SIGHASH_SINGLE) {
106
+ if (baseType === signature_1.Signature.SIGHASH_SINGLE) {
107
107
  if (inputNumber >= transaction.outputs.length) {
108
108
  throw new Error('SIGHASH_SINGLE: no corresponding output for input');
109
109
  }
110
- const w = new bufferwriter_js_1.BufferWriter();
110
+ const w = new bufferwriter_1.BufferWriter();
111
111
  transaction.outputs[inputNumber].toBufferWriter(w);
112
- const outputHash = hash_js_1.Hash.sha256sha256(w.toBuffer());
112
+ const outputHash = hash_1.Hash.sha256sha256(w.toBuffer());
113
113
  writer.write(outputHash);
114
114
  }
115
- if (baseType === signature_js_1.Signature.SIGHASH_ALL) {
115
+ if (baseType === signature_1.Signature.SIGHASH_ALL) {
116
116
  const outputHashes = transaction.outputs.map(output => {
117
- const w = new bufferwriter_js_1.BufferWriter();
117
+ const w = new bufferwriter_1.BufferWriter();
118
118
  output.toBufferWriter(w);
119
- return hash_js_1.Hash.sha256sha256(w.toBuffer());
119
+ return hash_1.Hash.sha256sha256(w.toBuffer());
120
120
  });
121
121
  const outputsMerkle = getMerkleRoot(outputHashes);
122
122
  writer.write(outputsMerkle.root);
123
123
  writer.writeUInt8(outputsMerkle.height);
124
124
  }
125
125
  writer.writeUInt32LE(transaction.nLockTime || 0);
126
- return hash_js_1.Hash.sha256sha256(writer.toBuffer());
126
+ return hash_1.Hash.sha256sha256(writer.toBuffer());
127
127
  }
128
128
  function sighashForForkId(transaction, sighashType, inputNumber, subscript, satoshisBN) {
129
129
  const input = transaction.inputs[inputNumber];
130
- preconditions_js_1.Preconditions.checkArgument(satoshisBN instanceof bn_js_1.BN, 'For ForkId=0 signatures, satoshis or complete input must be provided');
131
- let hashPrevouts = buffer_js_1.BufferUtil.emptyBuffer(32);
132
- let hashSequence = buffer_js_1.BufferUtil.emptyBuffer(32);
133
- let hashOutputs = buffer_js_1.BufferUtil.emptyBuffer(32);
134
- if (!(sighashType & signature_js_1.Signature.SIGHASH_ANYONECANPAY)) {
130
+ preconditions_1.Preconditions.checkArgument(satoshisBN instanceof bn_1.BN, 'For ForkId=0 signatures, satoshis or complete input must be provided');
131
+ let hashPrevouts = buffer_1.BufferUtil.emptyBuffer(32);
132
+ let hashSequence = buffer_1.BufferUtil.emptyBuffer(32);
133
+ let hashOutputs = buffer_1.BufferUtil.emptyBuffer(32);
134
+ if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY)) {
135
135
  hashPrevouts = GetPrevoutHash(transaction);
136
136
  }
137
- if (!(sighashType & signature_js_1.Signature.SIGHASH_ANYONECANPAY) &&
138
- (sighashType & 31) !== signature_js_1.Signature.SIGHASH_SINGLE &&
139
- (sighashType & 31) !== signature_js_1.Signature.SIGHASH_NONE) {
137
+ if (!(sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY) &&
138
+ (sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
139
+ (sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
140
140
  hashSequence = GetSequenceHash(transaction);
141
141
  }
142
- if ((sighashType & 31) !== signature_js_1.Signature.SIGHASH_SINGLE &&
143
- (sighashType & 31) !== signature_js_1.Signature.SIGHASH_NONE) {
142
+ if ((sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
143
+ (sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
144
144
  hashOutputs = GetOutputsHash(transaction);
145
145
  }
146
- else if ((sighashType & 31) === signature_js_1.Signature.SIGHASH_SINGLE &&
146
+ else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE &&
147
147
  inputNumber < transaction.outputs.length) {
148
148
  hashOutputs = GetOutputsHash(transaction, inputNumber);
149
149
  }
150
- const writer = new bufferwriter_js_1.BufferWriter();
150
+ const writer = new bufferwriter_1.BufferWriter();
151
151
  writer.writeUInt32LE(transaction.version || 2);
152
152
  writer.write(hashPrevouts);
153
153
  writer.write(hashSequence);
@@ -161,16 +161,16 @@ function sighashForForkId(transaction, sighashType, inputNumber, subscript, sato
161
161
  writer.writeUInt32LE(transaction.nLockTime || 0);
162
162
  writer.writeUInt32LE(sighashType >>> 0);
163
163
  const buf = writer.toBuffer();
164
- const hash = hash_js_1.Hash.sha256sha256(buf);
165
- return new bufferreader_js_1.BufferReader(hash).read(32);
164
+ const hash = hash_1.Hash.sha256sha256(buf);
165
+ return new bufferreader_1.BufferReader(hash).read(32);
166
166
  }
167
167
  function sighashLegacy(transaction, sighashType, inputNumber, subscript) {
168
168
  const input = transaction.inputs[inputNumber];
169
169
  function getHash(w) {
170
170
  const buf = w.toBuffer();
171
- return hash_js_1.Hash.sha256sha256(buf);
171
+ return hash_1.Hash.sha256sha256(buf);
172
172
  }
173
- const writer = new bufferwriter_js_1.BufferWriter();
173
+ const writer = new bufferwriter_1.BufferWriter();
174
174
  writer.writeUInt32LE(2);
175
175
  writer.writeVarintNum(transaction.inputs.length);
176
176
  for (let i = 0; i < transaction.inputs.length; i++) {
@@ -186,13 +186,13 @@ function sighashLegacy(transaction, sighashType, inputNumber, subscript) {
186
186
  writer.writeUInt32LENumber(txInput.sequenceNumber);
187
187
  }
188
188
  writer.writeVarintNum(transaction.outputs.length);
189
- if ((sighashType & 31) !== signature_js_1.Signature.SIGHASH_SINGLE &&
190
- (sighashType & 31) !== signature_js_1.Signature.SIGHASH_NONE) {
189
+ if ((sighashType & 31) !== signature_1.Signature.SIGHASH_SINGLE &&
190
+ (sighashType & 31) !== signature_1.Signature.SIGHASH_NONE) {
191
191
  for (const output of transaction.outputs) {
192
192
  output.toBufferWriter(writer);
193
193
  }
194
194
  }
195
- else if ((sighashType & 31) === signature_js_1.Signature.SIGHASH_SINGLE &&
195
+ else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE &&
196
196
  inputNumber < transaction.outputs.length) {
197
197
  transaction.outputs[inputNumber].toBufferWriter(writer);
198
198
  }
@@ -204,85 +204,85 @@ function sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, f
204
204
  if (flags === undefined) {
205
205
  flags = DEFAULT_SIGN_FLAGS_CONST;
206
206
  }
207
- const txcopy = transaction_js_1.Transaction.shallowCopy(transaction);
208
- subscript = new script_js_1.Script(subscript);
209
- if (flags & interpreter_js_1.Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION) {
207
+ const txcopy = transaction_1.Transaction.shallowCopy(transaction);
208
+ subscript = new script_1.Script(subscript);
209
+ if (flags & interpreter_1.Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION) {
210
210
  const forkValue = sighashType >> 8;
211
211
  const newForkValue = 0xff0000 | (forkValue ^ 0xdead);
212
212
  sighashType = (newForkValue << 8) | (sighashType & 0xff);
213
213
  }
214
214
  const algorithmBits = sighashType & SIGHASH_ALGORITHM_MASK;
215
- if (algorithmBits === signature_js_1.Signature.SIGHASH_LOTUS &&
216
- flags & interpreter_js_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
215
+ if (algorithmBits === signature_1.Signature.SIGHASH_LOTUS &&
216
+ flags & interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
217
217
  const spentOutputs = transaction.spentOutputs;
218
218
  if (!spentOutputs || spentOutputs.length !== transaction.inputs.length) {
219
219
  throw new Error('SIGHASH_LOTUS requires spent outputs for all inputs (ensure all inputs have output information)');
220
220
  }
221
221
  return sighashForLotus(txcopy, sighashType, inputNumber, spentOutputs);
222
222
  }
223
- if (algorithmBits === signature_js_1.Signature.SIGHASH_FORKID &&
224
- flags & interpreter_js_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
223
+ if (algorithmBits === signature_1.Signature.SIGHASH_FORKID &&
224
+ flags & interpreter_1.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID) {
225
225
  return sighashForForkId(txcopy, sighashType, inputNumber, subscript, satoshisBN);
226
226
  }
227
227
  subscript.removeCodeseparators();
228
228
  for (let i = 0; i < txcopy.inputs.length; i++) {
229
- txcopy.inputs[i] = new input_js_1.Input({
229
+ txcopy.inputs[i] = new input_1.Input({
230
230
  prevTxId: txcopy.inputs[i].prevTxId,
231
231
  outputIndex: txcopy.inputs[i].outputIndex,
232
232
  sequenceNumber: txcopy.inputs[i].sequenceNumber,
233
- script: (0, script_js_1.empty)(),
233
+ script: script_1.Script.empty(),
234
234
  });
235
235
  }
236
- txcopy.inputs[inputNumber] = new input_js_1.Input({
236
+ txcopy.inputs[inputNumber] = new input_1.Input({
237
237
  prevTxId: txcopy.inputs[inputNumber].prevTxId,
238
238
  outputIndex: txcopy.inputs[inputNumber].outputIndex,
239
239
  sequenceNumber: txcopy.inputs[inputNumber].sequenceNumber,
240
240
  script: subscript,
241
241
  });
242
- if ((sighashType & 31) === signature_js_1.Signature.SIGHASH_NONE ||
243
- (sighashType & 31) === signature_js_1.Signature.SIGHASH_SINGLE) {
242
+ if ((sighashType & 31) === signature_1.Signature.SIGHASH_NONE ||
243
+ (sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE) {
244
244
  for (let i = 0; i < txcopy.inputs.length; i++) {
245
245
  if (i !== inputNumber) {
246
246
  txcopy.inputs[i].sequenceNumber = 0;
247
247
  }
248
248
  }
249
249
  }
250
- if ((sighashType & 31) === signature_js_1.Signature.SIGHASH_NONE) {
250
+ if ((sighashType & 31) === signature_1.Signature.SIGHASH_NONE) {
251
251
  txcopy.outputs = [];
252
252
  }
253
- else if ((sighashType & 31) === signature_js_1.Signature.SIGHASH_SINGLE) {
253
+ else if ((sighashType & 31) === signature_1.Signature.SIGHASH_SINGLE) {
254
254
  if (inputNumber >= txcopy.outputs.length) {
255
- return Buffer.from(SIGHASH_SINGLE_BUG_CONST, 'hex');
255
+ return buffer_1.BufferUtil.from(SIGHASH_SINGLE_BUG_CONST, 'hex');
256
256
  }
257
257
  txcopy.outputs.length = inputNumber + 1;
258
258
  for (let i = 0; i < inputNumber; i++) {
259
- txcopy.outputs[i] = new output_js_1.Output({
260
- satoshis: bn_js_1.BN.fromBuffer(Buffer.from(BITS_64_ON_CONST, 'hex')),
261
- script: (0, script_js_1.empty)(),
259
+ txcopy.outputs[i] = new output_1.Output({
260
+ satoshis: bn_1.BN.fromBuffer(buffer_1.BufferUtil.from(BITS_64_ON_CONST, 'hex')),
261
+ script: script_1.Script.empty(),
262
262
  });
263
263
  }
264
264
  }
265
- if (sighashType & signature_js_1.Signature.SIGHASH_ANYONECANPAY) {
265
+ if (sighashType & signature_1.Signature.SIGHASH_ANYONECANPAY) {
266
266
  txcopy.inputs = [txcopy.inputs[inputNumber]];
267
267
  }
268
- const buf = new bufferwriter_js_1.BufferWriter()
268
+ const buf = new bufferwriter_1.BufferWriter()
269
269
  .write(txcopy.toBuffer())
270
270
  .writeInt32LE(sighashType >>> 0)
271
271
  .toBuffer();
272
- const hash = hash_js_1.Hash.sha256sha256(buf);
273
- return new bufferreader_js_1.BufferReader(hash).readReverse(32);
272
+ const hash = hash_1.Hash.sha256sha256(buf);
273
+ return new bufferreader_1.BufferReader(hash).readReverse(32);
274
274
  }
275
275
  function sign(transaction, privateKey, sighashType, inputIndex, subscript, satoshisBN, flags, signingMethod) {
276
276
  const hashbuf = sighash(transaction, sighashType, inputIndex, subscript, satoshisBN, flags);
277
277
  signingMethod = signingMethod || 'ecdsa';
278
278
  let sig;
279
279
  if (signingMethod === 'schnorr') {
280
- sig = schnorr_js_1.Schnorr.sign(hashbuf, privateKey, 'big');
280
+ sig = schnorr_1.Schnorr.sign(hashbuf, privateKey, 'big');
281
281
  sig.nhashtype = sighashType;
282
282
  return sig;
283
283
  }
284
284
  else if (signingMethod === 'ecdsa') {
285
- sig = ecdsa_js_1.ECDSA.sign(hashbuf, privateKey, 'big');
285
+ sig = ecdsa_1.ECDSA.sign(hashbuf, privateKey, 'big');
286
286
  sig.nhashtype = sighashType;
287
287
  return sig;
288
288
  }
@@ -291,39 +291,39 @@ function sign(transaction, privateKey, sighashType, inputIndex, subscript, satos
291
291
  }
292
292
  }
293
293
  function verify(transaction, signature, publicKey, inputIndex, subscript, satoshisBN, flags, signingMethod) {
294
- preconditions_js_1.Preconditions.checkArgument(transaction !== undefined, 'Transaction is required');
295
- preconditions_js_1.Preconditions.checkArgument(signature !== undefined && signature.nhashtype !== undefined, 'Signature with nhashtype is required');
294
+ preconditions_1.Preconditions.checkArgument(transaction !== undefined, 'Transaction is required');
295
+ preconditions_1.Preconditions.checkArgument(signature !== undefined && signature.nhashtype !== undefined, 'Signature with nhashtype is required');
296
296
  const hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript, satoshisBN, flags);
297
297
  signingMethod = signingMethod || 'ecdsa';
298
298
  if (signingMethod === 'schnorr') {
299
- return schnorr_js_1.Schnorr.verify(hashbuf, signature, publicKey, 'big');
299
+ return schnorr_1.Schnorr.verify(hashbuf, signature, publicKey, 'big');
300
300
  }
301
301
  else if (signingMethod === 'ecdsa') {
302
- return ecdsa_js_1.ECDSA.verify(hashbuf, signature, publicKey, 'big');
302
+ return ecdsa_1.ECDSA.verify(hashbuf, signature, publicKey, 'big');
303
303
  }
304
304
  else {
305
305
  throw new Error('Invalid signing method. Must be "ecdsa" or "schnorr"');
306
306
  }
307
307
  }
308
308
  function GetPrevoutHash(tx) {
309
- const writer = new bufferwriter_js_1.BufferWriter();
309
+ const writer = new bufferwriter_1.BufferWriter();
310
310
  for (const input of tx.inputs) {
311
311
  writer.writeReverse(input.prevTxId);
312
312
  writer.writeUInt32LE(input.outputIndex);
313
313
  }
314
314
  const buf = writer.toBuffer();
315
- return hash_js_1.Hash.sha256sha256(buf);
315
+ return hash_1.Hash.sha256sha256(buf);
316
316
  }
317
317
  function GetSequenceHash(tx) {
318
- const writer = new bufferwriter_js_1.BufferWriter();
318
+ const writer = new bufferwriter_1.BufferWriter();
319
319
  for (const input of tx.inputs) {
320
320
  writer.writeUInt32LENumber(input.sequenceNumber);
321
321
  }
322
322
  const buf = writer.toBuffer();
323
- return hash_js_1.Hash.sha256sha256(buf);
323
+ return hash_1.Hash.sha256sha256(buf);
324
324
  }
325
325
  function GetOutputsHash(tx, n) {
326
- const writer = new bufferwriter_js_1.BufferWriter();
326
+ const writer = new bufferwriter_1.BufferWriter();
327
327
  if (n === undefined) {
328
328
  for (const output of tx.outputs) {
329
329
  output.toBufferWriter(writer);
@@ -333,7 +333,7 @@ function GetOutputsHash(tx, n) {
333
333
  tx.outputs[n].toBufferWriter(writer);
334
334
  }
335
335
  const buf = writer.toBuffer();
336
- return hash_js_1.Hash.sha256sha256(buf);
336
+ return hash_1.Hash.sha256sha256(buf);
337
337
  }
338
338
  exports.DEFAULT_SIGN_FLAGS = DEFAULT_SIGN_FLAGS_CONST;
339
339
  exports.SIGHASH_SINGLE_BUG = SIGHASH_SINGLE_BUG_CONST;