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,16 @@
1
+ import { Input } from '../input';
2
+ export class TaprootInput extends Input {
3
+ internalPubKey;
4
+ merkleRoot;
5
+ controlBlock;
6
+ tapScript;
7
+ constructor(data) {
8
+ super(data);
9
+ if (data) {
10
+ this.internalPubKey = data.internalPubKey;
11
+ this.merkleRoot = data.merkleRoot;
12
+ this.controlBlock = data.controlBlock;
13
+ this.tapScript = data.tapScript;
14
+ }
15
+ }
16
+ }
@@ -1,37 +1,29 @@
1
- import { Preconditions } from '../util/preconditions.js';
2
- import { BitcoreError } from '../errors.js';
3
- import { BufferWriter } from '../encoding/bufferwriter.js';
4
- import { BufferUtil } from '../util/buffer.js';
5
- import { JSUtil } from '../util/js.js';
6
- import { Script, empty } from '../script.js';
7
- import { Opcode } from '../opcode.js';
8
- import { BN } from '../crypto/bn.js';
9
- import { Output } from './output.js';
10
- import { Signature } from '../crypto/signature.js';
11
- import { TransactionSignature } from './signature.js';
12
- import { sign, verify } from './sighash.js';
13
- import { Hash } from '../crypto/hash.js';
14
- import { tweakPrivateKey, TAPROOT_SIGHASH_TYPE, extractTaprootCommitment, } from '../taproot.js';
15
- import { musigNonceAgg, musigSigAgg } from '../crypto/musig2.js';
1
+ import { Preconditions } from '../util/preconditions';
2
+ import { BitcoreError } from '../errors';
3
+ import { BufferWriter } from '../encoding/bufferwriter';
4
+ import { BufferUtil } from '../util/buffer';
5
+ import { JSUtil } from '../util/js';
6
+ import { Script } from '../script';
7
+ import { Opcode } from '../opcode';
8
+ import { BN, Hash } from '../crypto';
9
+ import { Output } from './output';
10
+ import { muSig2NonceAgg, muSig2SigAgg } from '../crypto/musig2';
11
+ import { Signature } from '../crypto/signature';
12
+ import { TransactionSignature } from './signature';
13
+ import { sign, verify } from './sighash';
14
+ import { tweakPrivateKey, TAPROOT_SIGHASH_TYPE, extractTaprootCommitment, } from '../script/taproot';
15
+ const NULL_INDEX = 0xffffffff;
16
+ const NULL_HASH = BufferUtil.alloc(32);
16
17
  export class Input {
17
18
  static MAXINT = 0xffffffff;
18
19
  static DEFAULT_SEQNUMBER = 0xffffffff;
19
20
  static DEFAULT_LOCKTIME_SEQNUMBER = 0xfffffffe;
20
21
  static DEFAULT_RBF_SEQNUMBER = 0xfffffffd;
21
- static SEQUENCE_LOCKTIME_TYPE_FLAG = 0x400000;
22
- static SEQUENCE_LOCKTIME_DISABLE_FLAG = 0x80000000;
23
- static SEQUENCE_LOCKTIME_MASK = 0xffff;
22
+ static SEQUENCE_LOCKTIME_DISABLE_FLAG = 1 << 31;
23
+ static SEQUENCE_LOCKTIME_TYPE_FLAG = 1 << 22;
24
+ static SEQUENCE_LOCKTIME_MASK = 0x0000ffff;
24
25
  static SEQUENCE_LOCKTIME_GRANULARITY = 512;
25
26
  static SEQUENCE_BLOCKDIFF_LIMIT = 0xffff;
26
- static PublicKey;
27
- static PublicKeyHash;
28
- static Multisig;
29
- static MultisigScriptHash;
30
- static Taproot;
31
- static MuSigTaproot;
32
- static P2PKH;
33
- static P2SH;
34
- static P2TR;
35
27
  prevTxId;
36
28
  outputIndex;
37
29
  sequenceNumber;
@@ -54,13 +46,13 @@ export class Input {
54
46
  _fromObject(params) {
55
47
  let prevTxId;
56
48
  if (typeof params.prevTxId === 'string' && JSUtil.isHexa(params.prevTxId)) {
57
- prevTxId = Buffer.from(params.prevTxId, 'hex');
49
+ prevTxId = BufferUtil.from(params.prevTxId, 'hex');
58
50
  }
59
- else if (Buffer.isBuffer(params.prevTxId)) {
51
+ else if (BufferUtil.isBuffer(params.prevTxId)) {
60
52
  prevTxId = params.prevTxId;
61
53
  }
62
54
  else {
63
- prevTxId = Buffer.alloc(0);
55
+ prevTxId = BufferUtil.alloc(0);
64
56
  }
65
57
  this.output = params.output;
66
58
  this.prevTxId = prevTxId;
@@ -95,20 +87,20 @@ export class Input {
95
87
  this._scriptBuffer = script.toBuffer();
96
88
  }
97
89
  else if (script === null) {
98
- this._script = empty();
90
+ this._script = Script.empty();
99
91
  this._scriptBuffer = this._script.toBuffer();
100
92
  }
101
- else if (Buffer.isBuffer(script)) {
93
+ else if (BufferUtil.isBuffer(script)) {
102
94
  this._scriptBuffer = script;
103
95
  this._script = Script.fromBuffer(script);
104
96
  }
105
97
  else if (typeof script === 'string') {
106
98
  if (JSUtil.isHexa(script)) {
107
- this._scriptBuffer = Buffer.from(script, 'hex');
99
+ this._scriptBuffer = BufferUtil.from(script, 'hex');
108
100
  this._script = Script.fromBuffer(this._scriptBuffer);
109
101
  }
110
102
  else {
111
- this._scriptBuffer = Buffer.from(script, 'utf8');
103
+ this._scriptBuffer = BufferUtil.from(script, 'utf8');
112
104
  this._script = Script.fromBuffer(this._scriptBuffer);
113
105
  }
114
106
  }
@@ -118,12 +110,10 @@ export class Input {
118
110
  return this;
119
111
  }
120
112
  isNull() {
121
- return (this.prevTxId.toString('hex') ===
122
- '0000000000000000000000000000000000000000000000000000000000000000' &&
123
- this.outputIndex === 0xffffffff);
113
+ return this.prevTxId === NULL_HASH && this.outputIndex === NULL_INDEX;
124
114
  }
125
115
  isFinal() {
126
- return this.sequenceNumber !== 4294967295;
116
+ return this.sequenceNumber !== Input.DEFAULT_SEQNUMBER;
127
117
  }
128
118
  hasSequence() {
129
119
  return this.sequenceNumber !== Input.DEFAULT_SEQNUMBER;
@@ -160,7 +150,7 @@ export class Input {
160
150
  }
161
151
  toObject() {
162
152
  const obj = {
163
- prevTxId: Buffer.from(this.prevTxId).toString('hex'),
153
+ prevTxId: BufferUtil.from(this.prevTxId).toString('hex'),
164
154
  outputIndex: this.outputIndex,
165
155
  sequenceNumber: this.sequenceNumber,
166
156
  script: this._scriptBuffer.toString('hex'),
@@ -176,7 +166,9 @@ export class Input {
176
166
  }
177
167
  return obj;
178
168
  }
179
- toJSON = this.toObject;
169
+ toJSON() {
170
+ return this.toObject();
171
+ }
180
172
  static fromBufferReader(br) {
181
173
  const input = new Input();
182
174
  input.prevTxId = br.readReverse(32);
@@ -218,15 +210,15 @@ export class Input {
218
210
  }
219
211
  return (this.prevTxId.length === 32 &&
220
212
  this.outputIndex >= 0 &&
221
- this.outputIndex <= 0xffffffff &&
213
+ this.outputIndex <= NULL_INDEX &&
222
214
  this._scriptBuffer.length > 0);
223
215
  }
224
216
  clone() {
225
217
  return new Input({
226
- prevTxId: Buffer.from(this.prevTxId),
218
+ prevTxId: BufferUtil.from(this.prevTxId),
227
219
  outputIndex: this.outputIndex,
228
220
  sequenceNumber: this.sequenceNumber,
229
- scriptBuffer: Buffer.from(this._scriptBuffer),
221
+ scriptBuffer: BufferUtil.from(this._scriptBuffer),
230
222
  output: this.output,
231
223
  });
232
224
  }
@@ -445,9 +437,9 @@ export class MultisigInput extends Input {
445
437
  return this.signatures
446
438
  .filter(signature => signature !== undefined)
447
439
  .map(signature => {
448
- return Buffer.concat([
440
+ return BufferUtil.concat([
449
441
  signature.signature.toDER(signingMethod),
450
- Buffer.from([signature.sigtype]),
442
+ BufferUtil.from([signature.sigtype]),
451
443
  ]);
452
444
  });
453
445
  }
@@ -617,9 +609,9 @@ export class MultisigScriptHashInput extends Input {
617
609
  return this.signatures
618
610
  .filter(signature => signature !== undefined)
619
611
  .map(signature => {
620
- return Buffer.concat([
612
+ return BufferUtil.concat([
621
613
  signature.signature.toDER(signingMethod),
622
- Buffer.from([signature.sigtype]),
614
+ BufferUtil.from([signature.sigtype]),
623
615
  ]);
624
616
  });
625
617
  }
@@ -740,25 +732,23 @@ export class TaprootInput extends Input {
740
732
  tapScript;
741
733
  constructor(params) {
742
734
  super(params);
743
- if (params) {
744
- this.internalPubKey = params.internalPubKey;
745
- this.merkleRoot = params.merkleRoot;
746
- this.controlBlock = params.controlBlock;
747
- this.tapScript = params.tapScript;
748
- }
735
+ this.internalPubKey = params.internalPubKey;
736
+ this.merkleRoot = params.merkleRoot;
737
+ this.controlBlock = params.controlBlock;
738
+ this.tapScript = params.tapScript;
749
739
  }
750
740
  hasScriptTree() {
751
741
  if (!this.merkleRoot || this.merkleRoot.length !== 32) {
752
742
  return false;
753
743
  }
754
- return !this.merkleRoot.equals(Buffer.alloc(32));
744
+ return !this.merkleRoot.equals(BufferUtil.alloc(32));
755
745
  }
756
746
  isKeyPathOnly() {
757
747
  return !this.hasScriptTree();
758
748
  }
759
749
  getSignatures(transaction, privateKey, index, sigtype, hashData, signingMethod) {
760
750
  Preconditions.checkState(this.output instanceof Output, 'Output is required');
761
- Preconditions.checkState(this.output.script.isPayToTaproot(), 'Output must be Pay-To-Taproot');
751
+ Preconditions.checkState(this.output.script.isTaprootOut(), 'Output must be Pay-To-Taproot');
762
752
  const isKeyPath = this.isKeyPathOnly();
763
753
  if (isKeyPath) {
764
754
  sigtype = sigtype || TAPROOT_SIGHASH_TYPE;
@@ -778,7 +768,7 @@ export class TaprootInput extends Input {
778
768
  }
779
769
  }
780
770
  _getKeyPathSignatures(transaction, privateKey, index, sigtype, signingMethod) {
781
- const merkleRoot = this.merkleRoot || Buffer.alloc(32);
771
+ const merkleRoot = this.merkleRoot || BufferUtil.alloc(32);
782
772
  const tweakedPrivateKey = tweakPrivateKey(privateKey, merkleRoot);
783
773
  const signature = sign(transaction, tweakedPrivateKey, sigtype, index, this.output.script, new BN(this.output.satoshis.toString()), undefined, signingMethod);
784
774
  return [
@@ -846,7 +836,7 @@ export class TaprootInput extends Input {
846
836
  return 66;
847
837
  }
848
838
  }
849
- export class MuSigTaprootInput extends TaprootInput {
839
+ export class MuSig2TaprootInput extends TaprootInput {
850
840
  keyAggContext;
851
841
  publicNonces;
852
842
  aggregatedNonce;
@@ -854,14 +844,12 @@ export class MuSigTaprootInput extends TaprootInput {
854
844
  mySignerIndex;
855
845
  constructor(params) {
856
846
  super(params);
857
- if (params) {
858
- this.keyAggContext = params.keyAggContext;
859
- this.mySignerIndex = params.mySignerIndex;
860
- this.publicNonces = new Map();
861
- this.partialSignatures = new Map();
862
- }
847
+ this.keyAggContext = params.keyAggContext;
848
+ this.mySignerIndex = params.mySignerIndex;
849
+ this.publicNonces = new Map();
850
+ this.partialSignatures = new Map();
863
851
  }
864
- initMuSigSession(keyAggContext, mySignerIndex) {
852
+ initMuSig2Session(keyAggContext, mySignerIndex) {
865
853
  this.keyAggContext = keyAggContext;
866
854
  this.mySignerIndex = mySignerIndex;
867
855
  this.publicNonces = new Map();
@@ -894,7 +882,7 @@ export class MuSigTaprootInput extends TaprootInput {
894
882
  }
895
883
  noncesArray.push(nonce);
896
884
  }
897
- this.aggregatedNonce = musigNonceAgg(noncesArray);
885
+ this.aggregatedNonce = muSig2NonceAgg(noncesArray);
898
886
  return this;
899
887
  }
900
888
  addPartialSignature(signerIndex, partialSig) {
@@ -911,7 +899,7 @@ export class MuSigTaprootInput extends TaprootInput {
911
899
  const numSigners = this.keyAggContext.pubkeys.length;
912
900
  return this.partialSignatures.size === numSigners;
913
901
  }
914
- finalizeMuSigSignature(transaction, message) {
902
+ finalizeMuSig2Signature(transaction, message) {
915
903
  if (!this.hasAllPartialSignatures()) {
916
904
  throw new Error('Not all partial signatures received');
917
905
  }
@@ -927,7 +915,7 @@ export class MuSigTaprootInput extends TaprootInput {
927
915
  }
928
916
  partialSigsArray.push(partialSig);
929
917
  }
930
- const finalSignature = musigSigAgg(partialSigsArray, this.aggregatedNonce, message, commitment);
918
+ const finalSignature = muSig2SigAgg(partialSigsArray, this.aggregatedNonce, message, commitment);
931
919
  const script = new Script();
932
920
  script.add(finalSignature.toTxFormat('schnorr'));
933
921
  this.setScript(script);
@@ -940,12 +928,3 @@ export class MuSigTaprootInput extends TaprootInput {
940
928
  this.script.chunks.length > 0));
941
929
  }
942
930
  }
943
- Input.PublicKey = PublicKeyInput;
944
- Input.PublicKeyHash = PublicKeyHashInput;
945
- Input.Multisig = MultisigInput;
946
- Input.MultisigScriptHash = MultisigScriptHashInput;
947
- Input.Taproot = TaprootInput;
948
- Input.MuSigTaproot = MuSigTaprootInput;
949
- Input.P2PKH = PublicKeyHashInput;
950
- Input.P2SH = MultisigScriptHashInput;
951
- Input.P2TR = TaprootInput;
@@ -0,0 +1,85 @@
1
+ import { BufferReader } from '../encoding/bufferreader.js';
2
+ import { BufferWriter } from '../encoding/bufferwriter.js';
3
+ import { BufferUtil } from '../util/buffer.js';
4
+ export const OUTPOINT_SIZE = 36;
5
+ export class OutPoint {
6
+ static NULL_INDEX = 0xffffffff;
7
+ _txid;
8
+ _n;
9
+ constructor(txid, n) {
10
+ if (txid === undefined) {
11
+ this._txid = BufferUtil.alloc(32, 0);
12
+ this._n = OutPoint.NULL_INDEX;
13
+ }
14
+ else if (BufferUtil.isBuffer(txid)) {
15
+ if (txid.length !== 32) {
16
+ throw new TypeError(`OutPoint txid buffer must be 32 bytes, got ${txid.length}`);
17
+ }
18
+ this._txid = BufferUtil.from(txid);
19
+ this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
20
+ }
21
+ else if (typeof txid === 'string') {
22
+ if (txid.length !== 64) {
23
+ throw new TypeError(`OutPoint txid hex string must be 64 characters, got ${txid.length}`);
24
+ }
25
+ this._txid = BufferUtil.reverse(BufferUtil.from(txid, 'hex'));
26
+ this._n = n !== undefined ? n >>> 0 : OutPoint.NULL_INDEX;
27
+ }
28
+ else {
29
+ throw new TypeError('OutPoint txid must be a Buffer or hex string');
30
+ }
31
+ }
32
+ static fromObject(data) {
33
+ return new OutPoint(data.txid, data.outputIndex);
34
+ }
35
+ static fromBuffer(buf) {
36
+ const reader = new BufferReader(buf);
37
+ return OutPoint.fromBufferReader(reader);
38
+ }
39
+ static fromBufferReader(reader) {
40
+ const txidBuf = reader.read(32);
41
+ const n = reader.readUInt32LE();
42
+ const outpoint = new OutPoint();
43
+ outpoint._txid = txidBuf;
44
+ outpoint._n = n;
45
+ return outpoint;
46
+ }
47
+ isNull() {
48
+ return (this._n === OutPoint.NULL_INDEX && this._txid.every(byte => byte === 0));
49
+ }
50
+ getTxId() {
51
+ return BufferUtil.reverse(this._txid).toString('hex');
52
+ }
53
+ getTxIdBuffer() {
54
+ return BufferUtil.from(this._txid);
55
+ }
56
+ getN() {
57
+ return this._n;
58
+ }
59
+ toBuffer() {
60
+ const writer = new BufferWriter();
61
+ this.toBufferWriter(writer);
62
+ return writer.toBuffer();
63
+ }
64
+ toBufferWriter(writer) {
65
+ writer.write(this._txid);
66
+ writer.writeUInt32LE(this._n);
67
+ return writer;
68
+ }
69
+ toObject() {
70
+ return {
71
+ txid: this.getTxId(),
72
+ outputIndex: this._n,
73
+ };
74
+ }
75
+ toString() {
76
+ return `COutPoint(${this.getTxId().substring(0, 10)}, ${this._n})`;
77
+ }
78
+ equals(other) {
79
+ return this._txid.equals(other._txid) && this._n === other._n;
80
+ }
81
+ lessThan(other) {
82
+ const cmp = this._txid.compare(other._txid);
83
+ return cmp < 0 || (cmp === 0 && this._n < other._n);
84
+ }
85
+ }
@@ -1,9 +1,11 @@
1
+ import { BN } from '../crypto/bn.js';
1
2
  import { Preconditions } from '../util/preconditions.js';
2
3
  import { BitcoreError } from '../errors.js';
3
4
  import { BufferWriter } from '../encoding/bufferwriter.js';
5
+ import { BufferUtil } from '../util/buffer.js';
4
6
  import { JSUtil } from '../util/js.js';
5
7
  import { Script } from '../script.js';
6
- import { BN } from '../crypto/bn.js';
8
+ import { Opcode } from '../opcode.js';
7
9
  const MAX_SAFE_INTEGER = 0x1fffffffffffff;
8
10
  export class Output {
9
11
  satoshis;
@@ -19,7 +21,7 @@ export class Output {
19
21
  this.satoshis = 0;
20
22
  this._satoshisBN = new BN(0);
21
23
  }
22
- if (Buffer.isBuffer(args.script)) {
24
+ if (BufferUtil.isBuffer(args.script)) {
23
25
  this._scriptBuffer = args.script;
24
26
  }
25
27
  else if (args.scriptBuffer !== undefined) {
@@ -29,7 +31,7 @@ export class Output {
29
31
  this.setScript(args.script);
30
32
  }
31
33
  else {
32
- this._scriptBuffer = Buffer.alloc(0);
34
+ this._scriptBuffer = BufferUtil.alloc(0);
33
35
  }
34
36
  }
35
37
  else {
@@ -108,7 +110,7 @@ export class Output {
108
110
  this._scriptBuffer = this._script.toBuffer();
109
111
  this._script._isOutput = true;
110
112
  }
111
- else if (Buffer.isBuffer(script)) {
113
+ else if (BufferUtil.isBuffer(script)) {
112
114
  this.setScriptFromBuffer(script);
113
115
  }
114
116
  else {
@@ -150,7 +152,7 @@ export class Output {
150
152
  }
151
153
  return !!(this._script &&
152
154
  this._script.chunks.length > 0 &&
153
- this._script.chunks[0].opcodenum === 0x6a);
155
+ this._script.chunks[0].opcodenum === Opcode.OP_RETURN);
154
156
  }
155
157
  toObject() {
156
158
  return {
@@ -178,7 +180,7 @@ export class Output {
178
180
  obj.script = br.read(size);
179
181
  }
180
182
  else {
181
- obj.script = Buffer.from([]);
183
+ obj.script = BufferUtil.from([]);
182
184
  }
183
185
  return new Output(obj);
184
186
  }
@@ -214,10 +216,13 @@ export class Output {
214
216
  return new Output(data);
215
217
  }
216
218
  isPayToPublicKeyHash() {
217
- return this.script.isPayToPublicKeyHash();
219
+ return this.script.isPublicKeyHashOut();
218
220
  }
219
221
  isPayToScriptHash() {
220
- return this.script.isPayToScriptHash();
222
+ return this.script.isScriptHashOut();
223
+ }
224
+ isPayToTaproot() {
225
+ return this.script.isTaprootOut();
221
226
  }
222
227
  getAddress() {
223
228
  try {
@@ -1,23 +1,23 @@
1
- import { Signature } from '../crypto/signature.js';
2
- import { Script, empty } from '../script.js';
3
- import { Output } from './output.js';
4
- import { BufferReader } from '../encoding/bufferreader.js';
5
- import { BufferWriter } from '../encoding/bufferwriter.js';
6
- import { BN } from '../crypto/bn.js';
7
- import { Hash } from '../crypto/hash.js';
8
- import { ECDSA } from '../crypto/ecdsa.js';
9
- import { Schnorr } from '../crypto/schnorr.js';
10
- import { Preconditions } from '../util/preconditions.js';
11
- import { BufferUtil } from '../util/buffer.js';
12
- import { Interpreter } from '../script/interpreter.js';
13
- import { Transaction } from './transaction.js';
14
- import { Input } from './input.js';
1
+ import { Signature } from '../crypto/signature';
2
+ import { Script } from '../script';
3
+ import { Output } from './output';
4
+ import { BufferReader } from '../encoding/bufferreader';
5
+ import { BufferWriter } from '../encoding/bufferwriter';
6
+ import { BN } from '../crypto/bn';
7
+ import { Hash } from '../crypto/hash';
8
+ import { ECDSA } from '../crypto/ecdsa';
9
+ import { Schnorr } from '../crypto/schnorr';
10
+ import { Preconditions } from '../util/preconditions';
11
+ import { BufferUtil } from '../util/buffer';
12
+ import { Interpreter } from '../script/interpreter';
13
+ import { Transaction } from './transaction';
14
+ import { Input } from './input';
15
15
  const SIGHASH_SINGLE_BUG_CONST = '0000000000000000000000000000000000000000000000000000000000000001';
16
16
  const BITS_64_ON_CONST = 'ffffffffffffffff';
17
- const NULL_HASH = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
18
- const SIGHASH_ALGORITHM_MASK = 0x60;
17
+ const NULL_HASH = BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
18
+ const SIGHASH_ALGORITHM_MASK = Signature.SIGHASH_ALGORITHM_MASK;
19
19
  const DEFAULT_SIGN_FLAGS_CONST = 1 << 16;
20
- function GetForkId() {
20
+ function getForkId() {
21
21
  return 0;
22
22
  }
23
23
  function getMerkleRoot(hashes) {
@@ -32,7 +32,7 @@ function getMerkleRoot(hashes) {
32
32
  for (let i = 0; i < currentHashes.length; i += 2) {
33
33
  const left = currentHashes[i];
34
34
  const right = i + 1 < currentHashes.length ? currentHashes[i + 1] : NULL_HASH;
35
- const combined = Buffer.concat([left, right]);
35
+ const combined = BufferUtil.concat([left, right]);
36
36
  const pairHash = Hash.sha256sha256(combined);
37
37
  newHashes.push(pairHash);
38
38
  }
@@ -224,7 +224,7 @@ function sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, f
224
224
  prevTxId: txcopy.inputs[i].prevTxId,
225
225
  outputIndex: txcopy.inputs[i].outputIndex,
226
226
  sequenceNumber: txcopy.inputs[i].sequenceNumber,
227
- script: empty(),
227
+ script: Script.empty(),
228
228
  });
229
229
  }
230
230
  txcopy.inputs[inputNumber] = new Input({
@@ -246,13 +246,13 @@ function sighash(transaction, sighashType, inputNumber, subscript, satoshisBN, f
246
246
  }
247
247
  else if ((sighashType & 31) === Signature.SIGHASH_SINGLE) {
248
248
  if (inputNumber >= txcopy.outputs.length) {
249
- return Buffer.from(SIGHASH_SINGLE_BUG_CONST, 'hex');
249
+ return BufferUtil.from(SIGHASH_SINGLE_BUG_CONST, 'hex');
250
250
  }
251
251
  txcopy.outputs.length = inputNumber + 1;
252
252
  for (let i = 0; i < inputNumber; i++) {
253
253
  txcopy.outputs[i] = new Output({
254
- satoshis: BN.fromBuffer(Buffer.from(BITS_64_ON_CONST, 'hex')),
255
- script: empty(),
254
+ satoshis: BN.fromBuffer(BufferUtil.from(BITS_64_ON_CONST, 'hex')),
255
+ script: Script.empty(),
256
256
  });
257
257
  }
258
258
  }
@@ -1,9 +1,10 @@
1
- import { Preconditions } from '../util/preconditions.js';
2
- import { JSUtil } from '../util/js.js';
3
- import { PublicKey } from '../publickey.js';
4
- import { BitcoreError } from '../errors.js';
5
- import { Signature } from '../crypto/signature.js';
6
- import { isSchnorrSignature } from '../crypto/sigtype.js';
1
+ import { Preconditions } from '../util/preconditions';
2
+ import { BufferUtil } from '../util/buffer';
3
+ import { JSUtil } from '../util/js';
4
+ import { PublicKey } from '../publickey';
5
+ import { BitcoreError } from '../errors';
6
+ import { Signature } from '../crypto/signature';
7
+ import { isSchnorrSignature } from '../crypto/sigtype';
7
8
  export class TransactionSignature {
8
9
  publicKey;
9
10
  prevTxId;
@@ -43,19 +44,19 @@ export class TransactionSignature {
43
44
  _fromObject(arg) {
44
45
  this._checkObjectArgs(arg);
45
46
  this.publicKey = new PublicKey(arg.publicKey);
46
- this.prevTxId = Buffer.isBuffer(arg.prevTxId)
47
+ this.prevTxId = BufferUtil.isBuffer(arg.prevTxId)
47
48
  ? arg.prevTxId
48
- : Buffer.from(arg.prevTxId, 'hex');
49
+ : BufferUtil.from(arg.prevTxId, 'hex');
49
50
  this.outputIndex = arg.outputIndex;
50
51
  this.inputIndex = arg.inputIndex;
51
52
  this._sigtype = arg.sigtype;
52
53
  if (arg.signature instanceof Signature) {
53
54
  this.signature = arg.signature;
54
55
  }
55
- else if (Buffer.isBuffer(arg.signature)) {
56
+ else if (BufferUtil.isBuffer(arg.signature)) {
56
57
  const sigWithoutSighash = arg.signature.length > 64 &&
57
58
  arg.signature[arg.signature.length - 1] !== 0x30
58
- ? arg.signature.subarray(0, -1)
59
+ ? arg.signature.slice(0, -1)
59
60
  : arg.signature;
60
61
  if (isSchnorrSignature(sigWithoutSighash)) {
61
62
  const parsed = Signature.parseSchnorrEncodedSig(arg.signature);
@@ -68,10 +69,8 @@ export class TransactionSignature {
68
69
  }
69
70
  }
70
71
  else {
71
- const buf = Buffer.from(arg.signature, 'hex');
72
- const sigWithoutSighash = buf.length > 64 && buf[buf.length - 1] !== 0x30
73
- ? buf.subarray(0, -1)
74
- : buf;
72
+ const buf = BufferUtil.from(arg.signature, 'hex');
73
+ const sigWithoutSighash = buf.length > 64 && buf[buf.length - 1] !== 0x30 ? buf.slice(0, -1) : buf;
75
74
  if (isSchnorrSignature(sigWithoutSighash)) {
76
75
  const parsed = Signature.parseSchnorrEncodedSig(buf);
77
76
  const sig = new Signature(parsed.r, parsed.s);
@@ -93,9 +92,9 @@ export class TransactionSignature {
93
92
  Preconditions.checkArgument(arg.signature !== undefined, 'signature is required');
94
93
  Preconditions.checkArgument(arg.prevTxId !== undefined, 'prevTxId is required');
95
94
  Preconditions.checkState(arg.signature instanceof Signature ||
96
- Buffer.isBuffer(arg.signature) ||
95
+ BufferUtil.isBuffer(arg.signature) ||
97
96
  JSUtil.isHexa(arg.signature), 'signature must be a buffer or hexa value');
98
- Preconditions.checkState(Buffer.isBuffer(arg.prevTxId) || JSUtil.isHexa(arg.prevTxId), 'prevTxId must be a buffer or hexa value');
97
+ Preconditions.checkState(BufferUtil.isBuffer(arg.prevTxId) || JSUtil.isHexa(arg.prevTxId), 'prevTxId must be a buffer or hexa value');
99
98
  Preconditions.checkArgument(arg.sigtype !== undefined, 'sigtype is required');
100
99
  Preconditions.checkState(typeof arg.sigtype === 'number', 'sigtype must be a number');
101
100
  }
@@ -116,7 +115,7 @@ export class TransactionSignature {
116
115
  clone() {
117
116
  return new TransactionSignature({
118
117
  publicKey: this.publicKey,
119
- prevTxId: Buffer.from(this.prevTxId),
118
+ prevTxId: BufferUtil.from(this.prevTxId),
120
119
  outputIndex: this.outputIndex,
121
120
  inputIndex: this.inputIndex,
122
121
  signature: this.signature,