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,4 +1,6 @@
1
- import { BN } from './bn.js';
1
+ import { BN } from './bn';
2
+ import { BufferUtil } from '../util';
3
+ import { isSchnorrSignature } from './sigtype';
2
4
  export class Signature {
3
5
  r;
4
6
  s;
@@ -12,6 +14,8 @@ export class Signature {
12
14
  static SIGHASH_FORKID = 0x40;
13
15
  static SIGHASH_LOTUS = 0x60;
14
16
  static SIGHASH_ANYONECANPAY = 0x80;
17
+ static SIGHASH_RESERVED = 0x20;
18
+ static SIGHASH_ALGORITHM_MASK = 0x60;
15
19
  constructor(r, s, isSchnorr) {
16
20
  if (r instanceof BN) {
17
21
  this.set({
@@ -38,18 +42,18 @@ export class Signature {
38
42
  return this;
39
43
  }
40
44
  static fromCompact(buf) {
41
- if (!Buffer.isBuffer(buf)) {
45
+ if (!BufferUtil.isBuffer(buf)) {
42
46
  throw new Error('Argument is expected to be a Buffer');
43
47
  }
44
48
  const sig = new Signature(new BN(0), new BN(0));
45
49
  let compressed = true;
46
- let i = buf.subarray(0, 1)[0] - 27 - 4;
50
+ let i = buf.slice(0, 1)[0] - 27 - 4;
47
51
  if (i < 0) {
48
52
  compressed = false;
49
53
  i = i + 4;
50
54
  }
51
- const b2 = buf.subarray(1, 33);
52
- const b3 = buf.subarray(33, 65);
55
+ const b2 = buf.slice(1, 33);
56
+ const b3 = buf.slice(33, 65);
53
57
  if (!(i === 0 || i === 1 || i === 2 || i === 3)) {
54
58
  throw new Error('i must be 0, 1, 2, or 3');
55
59
  }
@@ -61,12 +65,13 @@ export class Signature {
61
65
  }
62
66
  sig.compressed = compressed;
63
67
  sig.i = i;
64
- sig.r = new BN(b2, 'le');
65
- sig.s = new BN(b3, 'le');
68
+ sig.r = BN.fromBuffer(b2);
69
+ sig.s = BN.fromBuffer(b3);
66
70
  return sig;
67
71
  }
68
72
  static fromDER(buf, strict = true) {
69
- if ((buf.length === 64 || buf.length === 65) && buf[0] !== 0x30) {
73
+ const rawSig = buf.length === 65 && buf[0] !== 0x30 ? buf.slice(0, 64) : buf;
74
+ if (isSchnorrSignature(rawSig) && buf[0] !== 0x30) {
70
75
  const obj = Signature.parseSchnorrEncodedSig(buf);
71
76
  const sig = new Signature(new BN(0), new BN(0));
72
77
  sig.r = obj.r;
@@ -74,7 +79,7 @@ export class Signature {
74
79
  sig.isSchnorr = true;
75
80
  return sig;
76
81
  }
77
- if (buf.length === 64 && buf[0] === 0x30) {
82
+ if (isSchnorrSignature(buf) && buf[0] === 0x30) {
78
83
  throw new Error('64 DER (ecdsa) signatures not allowed');
79
84
  }
80
85
  const obj = Signature.parseDER(buf, strict);
@@ -88,17 +93,17 @@ export class Signature {
88
93
  }
89
94
  static fromTxFormat(buf) {
90
95
  const nhashtype = buf.readUInt8(buf.length - 1);
91
- const derbuf = buf.subarray(0, buf.length - 1);
96
+ const derbuf = buf.slice(0, buf.length - 1);
92
97
  const sig = Signature.fromDER(derbuf, false);
93
98
  sig.nhashtype = nhashtype;
94
99
  return sig;
95
100
  }
96
101
  static fromDataFormat(buf) {
97
- const derbuf = buf.subarray(0, buf.length);
102
+ const derbuf = buf.slice(0, buf.length);
98
103
  return Signature.fromDER(derbuf, false);
99
104
  }
100
105
  static fromString(str) {
101
- const buf = Buffer.from(str, 'hex');
106
+ const buf = BufferUtil.from(str, 'hex');
102
107
  return Signature.fromDER(buf);
103
108
  }
104
109
  static fromSchnorr(buf) {
@@ -114,20 +119,20 @@ export class Signature {
114
119
  if (buf.length !== 64 && buf.length !== 65) {
115
120
  throw new Error(`Invalid Schnorr signature length: ${buf.length} bytes (expected 64 or 65)`);
116
121
  }
117
- const r = buf.subarray(0, 32);
118
- const s = buf.subarray(32, 64);
122
+ const r = buf.slice(0, 32);
123
+ const s = buf.slice(32, 64);
119
124
  let hashtype;
120
125
  if (buf.length === 65) {
121
- hashtype = buf.subarray(64, 65);
126
+ hashtype = buf.slice(64, 65);
122
127
  }
123
128
  return {
124
- r: new BN(r, 'be'),
125
- s: new BN(s, 'be'),
129
+ r: BN.fromBuffer(r),
130
+ s: BN.fromBuffer(s),
126
131
  nhashtype: hashtype,
127
132
  };
128
133
  }
129
134
  static parseDER(buf, strict = true) {
130
- if (!Buffer.isBuffer(buf)) {
135
+ if (!BufferUtil.isBuffer(buf)) {
131
136
  throw new Error('DER formatted signature should be a buffer');
132
137
  }
133
138
  const header = buf[0];
@@ -135,7 +140,7 @@ export class Signature {
135
140
  throw new Error('Header byte should be 0x30');
136
141
  }
137
142
  let length = buf[1];
138
- const buflength = buf.subarray(2).length;
143
+ const buflength = buf.slice(2).length;
139
144
  if (strict && length !== buflength) {
140
145
  throw new Error('Length byte should length of what follows');
141
146
  }
@@ -145,7 +150,7 @@ export class Signature {
145
150
  throw new Error('Integer byte for r should be 0x02');
146
151
  }
147
152
  const rlength = buf[2 + 1];
148
- const rbuf = buf.subarray(2 + 2, 2 + 2 + rlength);
153
+ const rbuf = buf.slice(2 + 2, 2 + 2 + rlength);
149
154
  const r = new BN(rbuf, 'be');
150
155
  if (rlength !== rbuf.length) {
151
156
  throw new Error('Length of r incorrect');
@@ -155,7 +160,7 @@ export class Signature {
155
160
  throw new Error('Integer byte for s should be 0x02');
156
161
  }
157
162
  const slength = buf[2 + 2 + rlength + 1];
158
- const sbuf = buf.subarray(2 + 2 + rlength + 2, 2 + 2 + rlength + 2 + slength);
163
+ const sbuf = buf.slice(2 + 2 + rlength + 2, 2 + 2 + rlength + 2 + slength);
159
164
  const s = new BN(sbuf, 'be');
160
165
  if (slength !== sbuf.length) {
161
166
  throw new Error('Length of s incorrect');
@@ -179,34 +184,38 @@ export class Signature {
179
184
  if (isCompressed === false) {
180
185
  val = val - 4;
181
186
  }
182
- const b1 = Buffer.from([val]);
183
- const b2 = this.r.toArrayLike(Buffer, 'le', 32);
184
- const b3 = this.s.toArrayLike(Buffer, 'le', 32);
185
- return Buffer.concat([b1, b2, b3]);
187
+ const b1 = BufferUtil.from([val]);
188
+ const b2 = this.r.toBuffer({ size: 32 });
189
+ const b3 = this.s.toBuffer({ size: 32 });
190
+ return BufferUtil.concat([b1, b2, b3]);
186
191
  }
187
192
  toDER(signingMethod = 'ecdsa') {
188
193
  if (signingMethod === 'schnorr') {
189
- return Buffer.concat([
190
- this.r.toArrayLike(Buffer, 'be', 32),
191
- this.s.toArrayLike(Buffer, 'be', 32),
194
+ return BufferUtil.concat([
195
+ this.r.toBuffer({ size: 32 }),
196
+ this.s.toBuffer({ size: 32 }),
192
197
  ]);
193
198
  }
194
- const rnbuf = this.r.toArrayLike(Buffer, 'be');
195
- const snbuf = this.s.toArrayLike(Buffer, 'be');
199
+ const rnbuf = this.r.toBuffer();
200
+ const snbuf = this.s.toBuffer();
196
201
  const rneg = (rnbuf[0] & 0x80) !== 0;
197
202
  const sneg = (snbuf[0] & 0x80) !== 0;
198
- const rbuf = rneg ? Buffer.concat([Buffer.from([0x00]), rnbuf]) : rnbuf;
199
- const sbuf = sneg ? Buffer.concat([Buffer.from([0x00]), snbuf]) : snbuf;
203
+ const rbuf = rneg
204
+ ? BufferUtil.concat([BufferUtil.from([0x00]), rnbuf])
205
+ : rnbuf;
206
+ const sbuf = sneg
207
+ ? BufferUtil.concat([BufferUtil.from([0x00]), snbuf])
208
+ : snbuf;
200
209
  const rlength = rbuf.length;
201
210
  const slength = sbuf.length;
202
211
  const length = 2 + rlength + 2 + slength;
203
212
  const rheader = 0x02;
204
213
  const sheader = 0x02;
205
214
  const header = 0x30;
206
- return Buffer.concat([
207
- Buffer.from([header, length, rheader, rlength]),
215
+ return BufferUtil.concat([
216
+ BufferUtil.from([header, length, rheader, rlength]),
208
217
  rbuf,
209
- Buffer.from([sheader, slength]),
218
+ BufferUtil.from([sheader, slength]),
210
219
  sbuf,
211
220
  ]);
212
221
  }
@@ -221,9 +230,12 @@ export class Signature {
221
230
  }
222
231
  toTxFormat(signingMethod) {
223
232
  const derbuf = this.toDER(signingMethod);
224
- const buf = Buffer.alloc(1);
225
- buf.writeUInt8(this.nhashtype || 0, 0);
226
- return Buffer.concat([derbuf, buf]);
233
+ const buf = BufferUtil.alloc(1);
234
+ const defaultSighash = this.isSchnorr
235
+ ? Signature.SIGHASH_ALL | Signature.SIGHASH_LOTUS
236
+ : 0;
237
+ buf.writeUInt8(this.nhashtype ?? defaultSighash, 0);
238
+ return BufferUtil.concat([derbuf, buf]);
227
239
  }
228
240
  static isDER(buf) {
229
241
  if (buf.length < 8 || buf.length > 72) {
@@ -271,8 +283,8 @@ export class Signature {
271
283
  return true;
272
284
  }
273
285
  hasLowS() {
274
- const lowSThreshold = new BN('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0', 16);
275
- if (this.s.lt(new BN(1)) || this.s.gt(lowSThreshold)) {
286
+ const lowSThreshold = BN.fromString('7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0', 'hex');
287
+ if (this.s.lt(BN.One) || this.s.gt(lowSThreshold)) {
276
288
  return false;
277
289
  }
278
290
  return true;
@@ -281,20 +293,20 @@ export class Signature {
281
293
  if (typeof this.nhashtype !== 'number') {
282
294
  return false;
283
295
  }
284
- if (this.nhashtype & Signature.SIGHASH_LOTUS) {
285
- const baseMask = ~(Signature.SIGHASH_LOTUS | Signature.SIGHASH_ANYONECANPAY) >>> 0;
286
- const baseType = this.nhashtype & baseMask;
287
- return (baseType >= Signature.SIGHASH_ALL &&
288
- baseType <= Signature.SIGHASH_SINGLE);
296
+ const baseType = this.nhashtype & 0x1f;
297
+ if (baseType < Signature.SIGHASH_ALL ||
298
+ baseType > Signature.SIGHASH_SINGLE) {
299
+ return false;
289
300
  }
290
- const mask = ~(Signature.SIGHASH_FORKID | Signature.SIGHASH_ANYONECANPAY) >>> 0;
291
- const temp = this.nhashtype & mask;
292
- if (temp < Signature.SIGHASH_ALL || temp > Signature.SIGHASH_SINGLE) {
301
+ const algorithm = this.nhashtype & Signature.SIGHASH_ALGORITHM_MASK;
302
+ if (algorithm !== 0x00 &&
303
+ algorithm !== Signature.SIGHASH_FORKID &&
304
+ algorithm !== Signature.SIGHASH_LOTUS) {
293
305
  return false;
294
306
  }
295
307
  return true;
296
308
  }
297
309
  static isTxDER(buf) {
298
- return Signature.isDER(buf.subarray(0, buf.length - 1));
310
+ return Signature.isDER(buf.slice(0, buf.length - 1));
299
311
  }
300
312
  }
@@ -11,7 +11,7 @@ export function isValidSignatureLength(sig) {
11
11
  if (sig.length === 64) {
12
12
  return true;
13
13
  }
14
- if (sig.length >= 9 && sig.length <= 73) {
14
+ if (sig.length >= 8 && sig.length <= 72) {
15
15
  return true;
16
16
  }
17
17
  return false;
@@ -1,9 +1,10 @@
1
1
  import bs58 from 'bs58';
2
+ import { BufferUtil } from '../util';
2
3
  const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'.split('');
3
4
  export class Base58 {
4
5
  buf;
5
6
  constructor(obj) {
6
- if (Buffer.isBuffer(obj)) {
7
+ if (BufferUtil.isBuffer(obj)) {
7
8
  const buf = obj;
8
9
  this.fromBuffer(buf);
9
10
  }
@@ -16,7 +17,7 @@ export class Base58 {
16
17
  }
17
18
  }
18
19
  static validCharacters(chars) {
19
- if (Buffer.isBuffer(chars)) {
20
+ if (BufferUtil.isBuffer(chars)) {
20
21
  chars = chars.toString();
21
22
  }
22
23
  return Array.from(chars).every(char => ALPHABET.includes(char));
@@ -26,7 +27,7 @@ export class Base58 {
26
27
  return this;
27
28
  }
28
29
  static encode(buf) {
29
- if (!Buffer.isBuffer(buf)) {
30
+ if (!BufferUtil.isBuffer(buf)) {
30
31
  throw new Error('Input should be a buffer');
31
32
  }
32
33
  return bs58.encode(buf);
@@ -35,7 +36,7 @@ export class Base58 {
35
36
  if (typeof str !== 'string') {
36
37
  throw new Error('Input should be a string');
37
38
  }
38
- return Buffer.from(bs58.decode(str));
39
+ return BufferUtil.from(bs58.decode(str));
39
40
  }
40
41
  fromBuffer(buf) {
41
42
  this.buf = buf;
@@ -1,82 +1,36 @@
1
- import { sha256 } from '@noble/hashes/sha256';
2
- const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
3
- const ALPHABET_MAP = {};
4
- for (let i = 0; i < ALPHABET.length; i++) {
5
- ALPHABET_MAP[ALPHABET[i]] = i;
6
- }
1
+ import { sha256 } from '@noble/hashes/sha2';
2
+ import bs58 from 'bs58';
3
+ import { BufferUtil } from '../util';
7
4
  export class Base58Check {
8
5
  static encode(buf) {
9
- if (!Buffer.isBuffer(buf)) {
6
+ if (!BufferUtil.isBuffer(buf)) {
10
7
  throw new Error('Input must be a Buffer');
11
8
  }
12
9
  const checksum = this.checksum(buf);
13
- const payload = Buffer.concat([buf, checksum]);
14
- return this.base58Encode(payload);
10
+ const payload = BufferUtil.concat([buf, checksum]);
11
+ return bs58.encode(payload);
15
12
  }
16
13
  static decode(str) {
17
14
  if (typeof str !== 'string') {
18
15
  throw new Error('Input must be a string');
19
16
  }
20
- const buf = this.base58Decode(str);
17
+ const buf = BufferUtil.from(bs58.decode(str));
21
18
  if (buf.length < 4) {
22
19
  throw new Error('Input string too short');
23
20
  }
24
- const data = buf.subarray(0, -4);
25
- const checksum = buf.subarray(-4);
21
+ const data = buf.slice(0, -4);
22
+ const checksum = buf.slice(-4);
26
23
  if (!this.validChecksum(data, checksum)) {
27
24
  throw new Error('Invalid checksum');
28
25
  }
29
26
  return data;
30
27
  }
31
28
  static checksum(data) {
32
- const hash1 = sha256(data);
33
- const hash2 = sha256(hash1);
34
- return Buffer.from(hash2).subarray(0, 4);
29
+ const hash = sha256(sha256(data));
30
+ return BufferUtil.from(hash).slice(0, 4);
35
31
  }
36
32
  static validChecksum(data, checksum) {
37
33
  const calculatedChecksum = this.checksum(data);
38
34
  return calculatedChecksum.equals(checksum);
39
35
  }
40
- static base58Encode(buf) {
41
- if (buf.length === 0)
42
- return '';
43
- let num = 0n;
44
- for (let i = 0; i < buf.length; i++) {
45
- num = num * 256n + BigInt(buf[i]);
46
- }
47
- let result = '';
48
- while (num > 0n) {
49
- result = ALPHABET[Number(num % 58n)] + result;
50
- num = num / 58n;
51
- }
52
- for (let i = 0; i < buf.length && buf[i] === 0; i++) {
53
- result = '1' + result;
54
- }
55
- return result;
56
- }
57
- static base58Decode(str) {
58
- if (str.length === 0)
59
- return Buffer.alloc(0);
60
- let num = 0n;
61
- let leadingZeros = 0;
62
- for (let i = 0; i < str.length; i++) {
63
- const char = str[i];
64
- if (ALPHABET_MAP[char] === undefined) {
65
- throw new Error(`Invalid character: ${char}`);
66
- }
67
- num = num * 58n + BigInt(ALPHABET_MAP[char]);
68
- }
69
- for (let i = 0; i < str.length && str[i] === '1'; i++) {
70
- leadingZeros++;
71
- }
72
- const bytes = [];
73
- while (num > 0n) {
74
- bytes.unshift(Number(num % 256n));
75
- num = num / 256n;
76
- }
77
- for (let i = 0; i < leadingZeros; i++) {
78
- bytes.unshift(0);
79
- }
80
- return Buffer.from(bytes);
81
- }
82
36
  }
@@ -1,6 +1,6 @@
1
- import { Preconditions } from '../util/preconditions.js';
2
- import { BN } from '../crypto/bn.js';
3
- import { BufferUtil } from '../util/buffer.js';
1
+ import { Preconditions } from '../util/preconditions';
2
+ import { BN } from '../crypto/bn';
3
+ import { BufferUtil } from '../util/buffer';
4
4
  export class BufferReader {
5
5
  buf;
6
6
  pos = 0;
@@ -8,13 +8,13 @@ export class BufferReader {
8
8
  if (buf === undefined) {
9
9
  return;
10
10
  }
11
- if (Buffer.isBuffer(buf)) {
11
+ if (BufferUtil.isBuffer(buf)) {
12
12
  this.set({
13
13
  buf: buf,
14
14
  });
15
15
  }
16
16
  else if (typeof buf === 'string') {
17
- const b = Buffer.from(buf, 'hex');
17
+ const b = BufferUtil.from(buf, 'hex');
18
18
  if (b.length * 2 !== buf.length) {
19
19
  throw new TypeError('Invalid hex string');
20
20
  }
@@ -112,7 +112,7 @@ export class BufferReader {
112
112
  }
113
113
  else {
114
114
  const data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
115
- bn = new BN(Buffer.from(data), 'le');
115
+ bn = new BN(BufferUtil.from(data), 'le');
116
116
  }
117
117
  this.pos = this.pos + 8;
118
118
  return bn;
@@ -180,7 +180,7 @@ export class BufferReader {
180
180
  }
181
181
  }
182
182
  reverse() {
183
- const buf = Buffer.alloc(this.buf.length);
183
+ const buf = BufferUtil.alloc(this.buf.length);
184
184
  for (let i = 0; i < buf.length; i++) {
185
185
  buf[i] = this.buf[this.buf.length - 1 - i];
186
186
  }
@@ -1,5 +1,5 @@
1
- import { BufferUtil } from '../util/buffer.js';
2
- import { BN } from '../crypto/bn.js';
1
+ import { BufferUtil } from '../util/buffer';
2
+ import { BN } from '../crypto/bn';
3
3
  export class BufferWriter {
4
4
  bufs = [];
5
5
  bufLen = 0;
@@ -24,7 +24,7 @@ export class BufferWriter {
24
24
  return this.concat();
25
25
  }
26
26
  concat() {
27
- return Buffer.concat(this.bufs, this.bufLen);
27
+ return BufferUtil.concat(this.bufs, this.bufLen);
28
28
  }
29
29
  write(buf) {
30
30
  if (!BufferUtil.isBuffer(buf)) {
@@ -43,49 +43,49 @@ export class BufferWriter {
43
43
  return this;
44
44
  }
45
45
  writeUInt8(n) {
46
- const buf = Buffer.alloc(1);
46
+ const buf = BufferUtil.alloc(1);
47
47
  buf.writeUInt8(n, 0);
48
48
  this.write(buf);
49
49
  return this;
50
50
  }
51
51
  writeUInt16BE(n) {
52
- const buf = Buffer.alloc(2);
52
+ const buf = BufferUtil.alloc(2);
53
53
  buf.writeUInt16BE(n, 0);
54
54
  this.write(buf);
55
55
  return this;
56
56
  }
57
57
  writeUInt16LE(n) {
58
- const buf = Buffer.alloc(2);
58
+ const buf = BufferUtil.alloc(2);
59
59
  buf.writeUInt16LE(n, 0);
60
60
  this.write(buf);
61
61
  return this;
62
62
  }
63
63
  writeUInt32BE(n) {
64
- const buf = Buffer.alloc(4);
64
+ const buf = BufferUtil.alloc(4);
65
65
  buf.writeUInt32BE(n, 0);
66
66
  this.write(buf);
67
67
  return this;
68
68
  }
69
69
  writeInt32LE(n) {
70
- const buf = Buffer.alloc(4);
70
+ const buf = BufferUtil.alloc(4);
71
71
  buf.writeInt32LE(n, 0);
72
72
  this.write(buf);
73
73
  return this;
74
74
  }
75
75
  writeUInt32LE(n) {
76
- const buf = Buffer.alloc(4);
76
+ const buf = BufferUtil.alloc(4);
77
77
  buf.writeUInt32LE(n, 0);
78
78
  this.write(buf);
79
79
  return this;
80
80
  }
81
81
  writeUInt48LE(n) {
82
- const buf = Buffer.alloc(6);
82
+ const buf = BufferUtil.alloc(6);
83
83
  buf.writeUIntLE(n, 0, 6);
84
84
  this.write(buf);
85
85
  return this;
86
86
  }
87
87
  writeUInt56LE(n) {
88
- const buf = Buffer.alloc(7);
88
+ const buf = BufferUtil.alloc(7);
89
89
  buf.writeUIntLE(n, 0, 7);
90
90
  this.write(buf);
91
91
  return this;
@@ -136,21 +136,21 @@ export class BufferWriter {
136
136
  static varintBufNum(n) {
137
137
  let buf;
138
138
  if (n < 253) {
139
- buf = Buffer.alloc(1);
139
+ buf = BufferUtil.alloc(1);
140
140
  buf.writeUInt8(n, 0);
141
141
  }
142
142
  else if (n < 0x10000) {
143
- buf = Buffer.alloc(1 + 2);
143
+ buf = BufferUtil.alloc(1 + 2);
144
144
  buf.writeUInt8(253, 0);
145
145
  buf.writeUInt16LE(n, 1);
146
146
  }
147
147
  else if (n < 0x100000000) {
148
- buf = Buffer.alloc(1 + 4);
148
+ buf = BufferUtil.alloc(1 + 4);
149
149
  buf.writeUInt8(254, 0);
150
150
  buf.writeUInt32LE(n, 1);
151
151
  }
152
152
  else {
153
- buf = Buffer.alloc(1 + 8);
153
+ buf = BufferUtil.alloc(1 + 8);
154
154
  buf.writeUInt8(255, 0);
155
155
  buf.writeInt32LE(n & -1, 1);
156
156
  buf.writeUInt32LE(Math.floor(n / 0x100000000), 5);
@@ -160,18 +160,18 @@ export class BufferWriter {
160
160
  static varintBufBN(bn) {
161
161
  const n = bn.toNumber();
162
162
  if (n < 253) {
163
- const buf = Buffer.alloc(1);
163
+ const buf = BufferUtil.alloc(1);
164
164
  buf.writeUInt8(n, 0);
165
165
  return buf;
166
166
  }
167
167
  else if (n < 0x10000) {
168
- const buf = Buffer.alloc(1 + 2);
168
+ const buf = BufferUtil.alloc(1 + 2);
169
169
  buf.writeUInt8(253, 0);
170
170
  buf.writeUInt16LE(n, 1);
171
171
  return buf;
172
172
  }
173
173
  else if (n < 0x100000000) {
174
- const buf = Buffer.alloc(1 + 4);
174
+ const buf = BufferUtil.alloc(1 + 4);
175
175
  buf.writeUInt8(254, 0);
176
176
  buf.writeUInt32LE(n, 1);
177
177
  return buf;
@@ -184,6 +184,3 @@ export class BufferWriter {
184
184
  }
185
185
  }
186
186
  }
187
- export function BufferWriterFactory(obj) {
188
- return new BufferWriter(obj);
189
- }
@@ -1,10 +1,11 @@
1
- import { BufferWriter } from './bufferwriter.js';
2
- import { BufferReader } from './bufferreader.js';
3
- import { BN } from '../crypto/bn.js';
1
+ import { BufferWriter } from './bufferwriter';
2
+ import { BufferReader } from './bufferreader';
3
+ import { BN } from '../crypto/bn';
4
+ import { BufferUtil } from '../util';
4
5
  export class Varint {
5
- buf = Buffer.alloc(0);
6
+ buf = BufferUtil.alloc(0);
6
7
  constructor(buf) {
7
- if (Buffer.isBuffer(buf)) {
8
+ if (BufferUtil.isBuffer(buf)) {
8
9
  this.buf = buf;
9
10
  }
10
11
  else if (typeof buf === 'number') {
@@ -26,7 +27,7 @@ export class Varint {
26
27
  }
27
28
  fromString(str) {
28
29
  this.set({
29
- buf: Buffer.from(str, 'hex'),
30
+ buf: BufferUtil.from(str, 'hex'),
30
31
  });
31
32
  return this;
32
33
  }
@@ -318,6 +318,7 @@ export class BitcoreError extends Error {
318
318
  return traverseNode(BitcoreError, spec);
319
319
  }
320
320
  static NotImplemented;
321
+ static MerkleBlock;
321
322
  static Script;
322
323
  static Precondition;
323
324
  static Transaction;