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,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BufferReader = void 0;
4
- const preconditions_js_1 = require("../util/preconditions.js");
5
- const bn_js_1 = require("../crypto/bn.js");
6
- const buffer_js_1 = require("../util/buffer.js");
4
+ const preconditions_1 = require("../util/preconditions");
5
+ const bn_1 = require("../crypto/bn");
6
+ const buffer_1 = require("../util/buffer");
7
7
  class BufferReader {
8
8
  buf;
9
9
  pos = 0;
@@ -11,13 +11,13 @@ class BufferReader {
11
11
  if (buf === undefined) {
12
12
  return;
13
13
  }
14
- if (Buffer.isBuffer(buf)) {
14
+ if (buffer_1.BufferUtil.isBuffer(buf)) {
15
15
  this.set({
16
16
  buf: buf,
17
17
  });
18
18
  }
19
19
  else if (typeof buf === 'string') {
20
- const b = Buffer.from(buf, 'hex');
20
+ const b = buffer_1.BufferUtil.from(buf, 'hex');
21
21
  if (b.length * 2 !== buf.length) {
22
22
  throw new TypeError('Invalid hex string');
23
23
  }
@@ -48,7 +48,7 @@ class BufferReader {
48
48
  return this.eof();
49
49
  }
50
50
  read(len) {
51
- preconditions_js_1.Preconditions.checkArgument(len !== undefined, 'len', 'Must specify a length');
51
+ preconditions_1.Preconditions.checkArgument(len !== undefined, 'len', 'Must specify a length');
52
52
  const buf = this.buf.slice(this.pos, this.pos + len);
53
53
  this.pos = this.pos + len;
54
54
  return buf;
@@ -90,7 +90,7 @@ class BufferReader {
90
90
  }
91
91
  readUInt56LEBN() {
92
92
  const buf = this.buf.slice(this.pos, this.pos + 7);
93
- const bn = bn_js_1.BN.fromBuffer(buf, { endian: 'little' });
93
+ const bn = bn_1.BN.fromBuffer(buf, { endian: 'little' });
94
94
  this.pos = this.pos + 7;
95
95
  return bn;
96
96
  }
@@ -101,7 +101,7 @@ class BufferReader {
101
101
  }
102
102
  readUInt64BEBN() {
103
103
  const buf = this.buf.slice(this.pos, this.pos + 8);
104
- const bn = bn_js_1.BN.fromBuffer(buf);
104
+ const bn = bn_1.BN.fromBuffer(buf);
105
105
  this.pos = this.pos + 8;
106
106
  return bn;
107
107
  }
@@ -111,11 +111,11 @@ class BufferReader {
111
111
  const combined = first * 0x100000000 + second;
112
112
  let bn;
113
113
  if (combined <= 0x1fffffffffffff) {
114
- bn = new bn_js_1.BN(combined);
114
+ bn = new bn_1.BN(combined);
115
115
  }
116
116
  else {
117
117
  const data = Array.prototype.slice.call(this.buf, this.pos, this.pos + 8);
118
- bn = new bn_js_1.BN(Buffer.from(data), 'le');
118
+ bn = new bn_1.BN(buffer_1.BufferUtil.from(data), 'le');
119
119
  }
120
120
  this.pos = this.pos + 8;
121
121
  return bn;
@@ -123,7 +123,7 @@ class BufferReader {
123
123
  readUInt32LEBN() {
124
124
  const value = this.buf.readUInt32LE(this.pos);
125
125
  this.pos = this.pos + 4;
126
- return new bn_js_1.BN(value);
126
+ return new bn_1.BN(value);
127
127
  }
128
128
  readVarintNum() {
129
129
  const first = this.readUInt8();
@@ -149,7 +149,7 @@ class BufferReader {
149
149
  readVarLengthBuffer() {
150
150
  const len = this.readVarintNum();
151
151
  const buf = this.read(len);
152
- preconditions_js_1.Preconditions.checkState(buf.length === len, 'Invalid length while reading varlength buffer. ' +
152
+ preconditions_1.Preconditions.checkState(buf.length === len, 'Invalid length while reading varlength buffer. ' +
153
153
  'Expected to read: ' +
154
154
  len +
155
155
  ' and read ' +
@@ -173,17 +173,17 @@ class BufferReader {
173
173
  const first = this.readUInt8();
174
174
  switch (first) {
175
175
  case 0xfd:
176
- return new bn_js_1.BN(this.readUInt16LE());
176
+ return new bn_1.BN(this.readUInt16LE());
177
177
  case 0xfe:
178
- return new bn_js_1.BN(this.readUInt32LE());
178
+ return new bn_1.BN(this.readUInt32LE());
179
179
  case 0xff:
180
180
  return this.readUInt64LEBN();
181
181
  default:
182
- return new bn_js_1.BN(first);
182
+ return new bn_1.BN(first);
183
183
  }
184
184
  }
185
185
  reverse() {
186
- const buf = Buffer.alloc(this.buf.length);
186
+ const buf = buffer_1.BufferUtil.alloc(this.buf.length);
187
187
  for (let i = 0; i < buf.length; i++) {
188
188
  buf[i] = this.buf[this.buf.length - 1 - i];
189
189
  }
@@ -196,7 +196,7 @@ class BufferReader {
196
196
  }
197
197
  const buf = this.buf.slice(this.pos, this.pos + len);
198
198
  this.pos = this.pos + len;
199
- return buffer_js_1.BufferUtil.reverse(buf);
199
+ return buffer_1.BufferUtil.reverse(buf);
200
200
  }
201
201
  }
202
202
  exports.BufferReader = BufferReader;
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BufferWriter = void 0;
4
- exports.BufferWriterFactory = BufferWriterFactory;
5
- const buffer_js_1 = require("../util/buffer.js");
6
- const bn_js_1 = require("../crypto/bn.js");
4
+ const buffer_1 = require("../util/buffer");
5
+ const bn_1 = require("../crypto/bn");
7
6
  class BufferWriter {
8
7
  bufs = [];
9
8
  bufLen = 0;
@@ -28,10 +27,10 @@ class BufferWriter {
28
27
  return this.concat();
29
28
  }
30
29
  concat() {
31
- return Buffer.concat(this.bufs, this.bufLen);
30
+ return buffer_1.BufferUtil.concat(this.bufs, this.bufLen);
32
31
  }
33
32
  write(buf) {
34
- if (!buffer_js_1.BufferUtil.isBuffer(buf)) {
33
+ if (!buffer_1.BufferUtil.isBuffer(buf)) {
35
34
  throw new Error('Expected Buffer');
36
35
  }
37
36
  this.bufs.push(buf);
@@ -39,57 +38,57 @@ class BufferWriter {
39
38
  return this;
40
39
  }
41
40
  writeReverse(buf) {
42
- if (!buffer_js_1.BufferUtil.isBuffer(buf)) {
41
+ if (!buffer_1.BufferUtil.isBuffer(buf)) {
43
42
  throw new Error('Expected Buffer');
44
43
  }
45
- this.bufs.push(buffer_js_1.BufferUtil.reverse(buf));
44
+ this.bufs.push(buffer_1.BufferUtil.reverse(buf));
46
45
  this.bufLen += buf.length;
47
46
  return this;
48
47
  }
49
48
  writeUInt8(n) {
50
- const buf = Buffer.alloc(1);
49
+ const buf = buffer_1.BufferUtil.alloc(1);
51
50
  buf.writeUInt8(n, 0);
52
51
  this.write(buf);
53
52
  return this;
54
53
  }
55
54
  writeUInt16BE(n) {
56
- const buf = Buffer.alloc(2);
55
+ const buf = buffer_1.BufferUtil.alloc(2);
57
56
  buf.writeUInt16BE(n, 0);
58
57
  this.write(buf);
59
58
  return this;
60
59
  }
61
60
  writeUInt16LE(n) {
62
- const buf = Buffer.alloc(2);
61
+ const buf = buffer_1.BufferUtil.alloc(2);
63
62
  buf.writeUInt16LE(n, 0);
64
63
  this.write(buf);
65
64
  return this;
66
65
  }
67
66
  writeUInt32BE(n) {
68
- const buf = Buffer.alloc(4);
67
+ const buf = buffer_1.BufferUtil.alloc(4);
69
68
  buf.writeUInt32BE(n, 0);
70
69
  this.write(buf);
71
70
  return this;
72
71
  }
73
72
  writeInt32LE(n) {
74
- const buf = Buffer.alloc(4);
73
+ const buf = buffer_1.BufferUtil.alloc(4);
75
74
  buf.writeInt32LE(n, 0);
76
75
  this.write(buf);
77
76
  return this;
78
77
  }
79
78
  writeUInt32LE(n) {
80
- const buf = Buffer.alloc(4);
79
+ const buf = buffer_1.BufferUtil.alloc(4);
81
80
  buf.writeUInt32LE(n, 0);
82
81
  this.write(buf);
83
82
  return this;
84
83
  }
85
84
  writeUInt48LE(n) {
86
- const buf = Buffer.alloc(6);
85
+ const buf = buffer_1.BufferUtil.alloc(6);
87
86
  buf.writeUIntLE(n, 0, 6);
88
87
  this.write(buf);
89
88
  return this;
90
89
  }
91
90
  writeUInt56LE(n) {
92
- const buf = Buffer.alloc(7);
91
+ const buf = buffer_1.BufferUtil.alloc(7);
93
92
  buf.writeUIntLE(n, 0, 7);
94
93
  this.write(buf);
95
94
  return this;
@@ -110,7 +109,7 @@ class BufferWriter {
110
109
  return this;
111
110
  }
112
111
  writeUInt64LEBigInt(value) {
113
- const bn = new bn_js_1.BN(value.toString());
112
+ const bn = new bn_1.BN(value.toString());
114
113
  return this.writeUInt64LEBN(bn);
115
114
  }
116
115
  writeUInt32LEBN(bn) {
@@ -140,21 +139,21 @@ class BufferWriter {
140
139
  static varintBufNum(n) {
141
140
  let buf;
142
141
  if (n < 253) {
143
- buf = Buffer.alloc(1);
142
+ buf = buffer_1.BufferUtil.alloc(1);
144
143
  buf.writeUInt8(n, 0);
145
144
  }
146
145
  else if (n < 0x10000) {
147
- buf = Buffer.alloc(1 + 2);
146
+ buf = buffer_1.BufferUtil.alloc(1 + 2);
148
147
  buf.writeUInt8(253, 0);
149
148
  buf.writeUInt16LE(n, 1);
150
149
  }
151
150
  else if (n < 0x100000000) {
152
- buf = Buffer.alloc(1 + 4);
151
+ buf = buffer_1.BufferUtil.alloc(1 + 4);
153
152
  buf.writeUInt8(254, 0);
154
153
  buf.writeUInt32LE(n, 1);
155
154
  }
156
155
  else {
157
- buf = Buffer.alloc(1 + 8);
156
+ buf = buffer_1.BufferUtil.alloc(1 + 8);
158
157
  buf.writeUInt8(255, 0);
159
158
  buf.writeInt32LE(n & -1, 1);
160
159
  buf.writeUInt32LE(Math.floor(n / 0x100000000), 5);
@@ -164,18 +163,18 @@ class BufferWriter {
164
163
  static varintBufBN(bn) {
165
164
  const n = bn.toNumber();
166
165
  if (n < 253) {
167
- const buf = Buffer.alloc(1);
166
+ const buf = buffer_1.BufferUtil.alloc(1);
168
167
  buf.writeUInt8(n, 0);
169
168
  return buf;
170
169
  }
171
170
  else if (n < 0x10000) {
172
- const buf = Buffer.alloc(1 + 2);
171
+ const buf = buffer_1.BufferUtil.alloc(1 + 2);
173
172
  buf.writeUInt8(253, 0);
174
173
  buf.writeUInt16LE(n, 1);
175
174
  return buf;
176
175
  }
177
176
  else if (n < 0x100000000) {
178
- const buf = Buffer.alloc(1 + 4);
177
+ const buf = buffer_1.BufferUtil.alloc(1 + 4);
179
178
  buf.writeUInt8(254, 0);
180
179
  buf.writeUInt32LE(n, 1);
181
180
  return buf;
@@ -189,6 +188,3 @@ class BufferWriter {
189
188
  }
190
189
  }
191
190
  exports.BufferWriter = BufferWriter;
192
- function BufferWriterFactory(obj) {
193
- return new BufferWriter(obj);
194
- }
@@ -1,20 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Varint = void 0;
4
- const bufferwriter_js_1 = require("./bufferwriter.js");
5
- const bufferreader_js_1 = require("./bufferreader.js");
6
- const bn_js_1 = require("../crypto/bn.js");
4
+ const bufferwriter_1 = require("./bufferwriter");
5
+ const bufferreader_1 = require("./bufferreader");
6
+ const bn_1 = require("../crypto/bn");
7
+ const util_1 = require("../util");
7
8
  class Varint {
8
- buf = Buffer.alloc(0);
9
+ buf = util_1.BufferUtil.alloc(0);
9
10
  constructor(buf) {
10
- if (Buffer.isBuffer(buf)) {
11
+ if (util_1.BufferUtil.isBuffer(buf)) {
11
12
  this.buf = buf;
12
13
  }
13
14
  else if (typeof buf === 'number') {
14
15
  const num = buf;
15
16
  this.fromNumber(num);
16
17
  }
17
- else if (buf instanceof bn_js_1.BN) {
18
+ else if (buf instanceof bn_1.BN) {
18
19
  const bn = buf;
19
20
  this.fromBN(bn);
20
21
  }
@@ -29,7 +30,7 @@ class Varint {
29
30
  }
30
31
  fromString(str) {
31
32
  this.set({
32
- buf: Buffer.from(str, 'hex'),
33
+ buf: util_1.BufferUtil.from(str, 'hex'),
33
34
  });
34
35
  return this;
35
36
  }
@@ -45,21 +46,21 @@ class Varint {
45
46
  return this;
46
47
  }
47
48
  fromBN(bn) {
48
- this.buf = bufferwriter_js_1.BufferWriter.varintBufBN(bn);
49
+ this.buf = bufferwriter_1.BufferWriter.varintBufBN(bn);
49
50
  return this;
50
51
  }
51
52
  fromNumber(num) {
52
- this.buf = new bufferwriter_js_1.BufferWriter().writeVarintNum(num).concat();
53
+ this.buf = new bufferwriter_1.BufferWriter().writeVarintNum(num).concat();
53
54
  return this;
54
55
  }
55
56
  toBuffer() {
56
57
  return this.buf;
57
58
  }
58
59
  toBN() {
59
- return new bufferreader_js_1.BufferReader(this.buf).readVarintBN();
60
+ return new bufferreader_1.BufferReader(this.buf).readVarintBN();
60
61
  }
61
62
  toNumber() {
62
- return new bufferreader_js_1.BufferReader(this.buf).readVarintNum();
63
+ return new bufferreader_1.BufferReader(this.buf).readVarintNum();
63
64
  }
64
65
  }
65
66
  exports.Varint = Varint;
@@ -321,6 +321,7 @@ class BitcoreError extends Error {
321
321
  return traverseNode(BitcoreError, spec);
322
322
  }
323
323
  static NotImplemented;
324
+ static MerkleBlock;
324
325
  static Script;
325
326
  static Precondition;
326
327
  static Transaction;
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HDPrivateKey = void 0;
4
- const bn_js_1 = require("./crypto/bn.js");
5
- const privatekey_js_1 = require("./privatekey.js");
6
- const publickey_js_1 = require("./publickey.js");
7
- const point_js_1 = require("./crypto/point.js");
8
- const networks_js_1 = require("./networks.js");
9
- const hash_js_1 = require("./crypto/hash.js");
10
- const random_js_1 = require("./crypto/random.js");
11
- const base58check_js_1 = require("./encoding/base58check.js");
12
- const js_js_1 = require("./util/js.js");
13
- const preconditions_js_1 = require("./util/preconditions.js");
14
- const hdpublickey_js_1 = require("./hdpublickey.js");
4
+ const bn_1 = require("./crypto/bn");
5
+ const privatekey_1 = require("./privatekey");
6
+ const publickey_1 = require("./publickey");
7
+ const point_1 = require("./crypto/point");
8
+ const networks_1 = require("./networks");
9
+ const hash_1 = require("./crypto/hash");
10
+ const random_1 = require("./crypto/random");
11
+ const base58check_1 = require("./encoding/base58check");
12
+ const util_1 = require("./util");
13
+ const preconditions_1 = require("./util/preconditions");
14
+ const hdpublickey_1 = require("./hdpublickey");
15
15
  class HDPrivateKey {
16
16
  privateKey;
17
17
  network;
@@ -32,22 +32,22 @@ class HDPrivateKey {
32
32
  return data;
33
33
  }
34
34
  if (data === undefined ||
35
- (typeof data === 'string' && (0, networks_js_1.get)(data)) ||
36
- data instanceof networks_js_1.Network) {
35
+ (typeof data === 'string' && (0, networks_1.get)(data)) ||
36
+ data instanceof networks_1.Network) {
37
37
  const targetNetwork = data
38
- ? (0, networks_js_1.get)(data)
38
+ ? (0, networks_1.get)(data)
39
39
  : network
40
- ? (0, networks_js_1.get)(network)
40
+ ? (0, networks_1.get)(network)
41
41
  : undefined;
42
42
  data = HDPrivateKey._getRandomData(targetNetwork);
43
43
  }
44
44
  const info = this._classifyArguments(data);
45
45
  if (network && info.network) {
46
- const resolvedNetwork = (0, networks_js_1.get)(network);
46
+ const resolvedNetwork = (0, networks_1.get)(network);
47
47
  if (resolvedNetwork) {
48
48
  info.network = resolvedNetwork;
49
49
  if (info.privateKey) {
50
- info.privateKey = new privatekey_js_1.PrivateKey(info.privateKey.bn, resolvedNetwork);
50
+ info.privateKey = new privatekey_1.PrivateKey(info.privateKey.bn, resolvedNetwork);
51
51
  }
52
52
  }
53
53
  }
@@ -63,7 +63,7 @@ class HDPrivateKey {
63
63
  if (typeof data === 'string') {
64
64
  return HDPrivateKey._transformString(data);
65
65
  }
66
- else if (Buffer.isBuffer(data)) {
66
+ else if (util_1.BufferUtil.isBuffer(data)) {
67
67
  try {
68
68
  const str = data.toString('utf8');
69
69
  if (HDPrivateKey.isValidSerialized(str)) {
@@ -87,13 +87,13 @@ class HDPrivateKey {
87
87
  }
88
88
  }
89
89
  static _transformString(str) {
90
- if (!js_js_1.JSUtil.isHexa(str)) {
90
+ if (!util_1.JSUtil.isHexa(str)) {
91
91
  return HDPrivateKey._transformSerialized(str);
92
92
  }
93
- return HDPrivateKey._transformBuffer(Buffer.from(str, 'hex'));
93
+ return HDPrivateKey._transformBuffer(util_1.BufferUtil.from(str, 'hex'));
94
94
  }
95
95
  static _transformSerialized(str) {
96
- const buf = base58check_js_1.Base58Check.decode(str);
96
+ const buf = base58check_1.Base58Check.decode(str);
97
97
  return HDPrivateKey._transformBuffer(buf);
98
98
  }
99
99
  static _transformBuffer(buf) {
@@ -101,68 +101,68 @@ class HDPrivateKey {
101
101
  throw new Error('Invalid HDPrivateKey buffer length');
102
102
  }
103
103
  const version = buf.readUInt32BE(0);
104
- const network = (0, networks_js_1.get)(version, 'xprivkey');
104
+ const network = (0, networks_1.get)(version, 'xprivkey');
105
105
  if (!network) {
106
106
  throw new Error('Invalid HDPrivateKey network');
107
107
  }
108
108
  const depth = buf.readUInt8(4);
109
- const parentFingerPrint = buf.subarray(5, 9);
109
+ const parentFingerPrint = buf.slice(5, 9);
110
110
  const childIndex = buf.readUInt32BE(9);
111
- const chainCode = buf.subarray(13, 45);
112
- const privateKeyBuffer = buf.subarray(46, 78);
111
+ const chainCode = buf.slice(13, 45);
112
+ const privateKeyBuffer = buf.slice(46, 78);
113
113
  return {
114
114
  network,
115
115
  depth,
116
116
  parentFingerPrint,
117
117
  childIndex,
118
118
  chainCode,
119
- privateKey: new privatekey_js_1.PrivateKey(privateKeyBuffer, network),
119
+ privateKey: new privatekey_1.PrivateKey(privateKeyBuffer, network),
120
120
  };
121
121
  }
122
122
  static _transformObject(obj) {
123
- const network = (0, networks_js_1.get)(obj.network);
123
+ const network = (0, networks_1.get)(obj.network);
124
124
  if (!network) {
125
125
  throw new Error('Invalid network');
126
126
  }
127
127
  return {
128
128
  network,
129
129
  depth: obj.depth,
130
- parentFingerPrint: Buffer.from(obj.parentFingerPrint, 'hex'),
130
+ parentFingerPrint: util_1.BufferUtil.from(obj.parentFingerPrint, 'hex'),
131
131
  childIndex: obj.childIndex,
132
- chainCode: Buffer.from(obj.chainCode, 'hex'),
133
- privateKey: new privatekey_js_1.PrivateKey(obj.privateKey, network),
132
+ chainCode: util_1.BufferUtil.from(obj.chainCode, 'hex'),
133
+ privateKey: new privatekey_1.PrivateKey(obj.privateKey, network),
134
134
  };
135
135
  }
136
136
  static _getRandomData(network) {
137
- const seed = random_js_1.Random.getRandomBuffer(64);
137
+ const seed = random_1.Random.getRandomBuffer(64);
138
138
  return HDPrivateKey._fromSeed(seed, network);
139
139
  }
140
140
  static _fromSeed(seed, network) {
141
- const hash = hash_js_1.Hash.sha512hmac(seed, Buffer.from('Bitcoin seed'));
142
- const privateKeyBuffer = hash.subarray(0, 32);
143
- const chainCode = hash.subarray(32, 64);
144
- const resolvedNetwork = network ? (0, networks_js_1.get)(network) : networks_js_1.defaultNetwork;
141
+ const hash = hash_1.Hash.sha512hmac(seed, util_1.BufferUtil.from('Bitcoin seed'));
142
+ const privateKeyBuffer = hash.slice(0, 32);
143
+ const chainCode = hash.slice(32, 64);
144
+ const resolvedNetwork = network ? (0, networks_1.get)(network) : networks_1.defaultNetwork;
145
145
  if (!resolvedNetwork) {
146
146
  throw new Error('Invalid network');
147
147
  }
148
148
  return {
149
149
  network: resolvedNetwork,
150
150
  depth: 0,
151
- parentFingerPrint: Buffer.alloc(4),
151
+ parentFingerPrint: util_1.BufferUtil.alloc(4),
152
152
  childIndex: 0,
153
153
  chainCode,
154
- privateKey: new privatekey_js_1.PrivateKey(privateKeyBuffer, resolvedNetwork),
154
+ privateKey: new privatekey_1.PrivateKey(privateKeyBuffer, resolvedNetwork),
155
155
  };
156
156
  }
157
157
  _buildFromObject(info) {
158
- preconditions_js_1.Preconditions.checkArgument(!!info.network, 'network', 'Network is required');
159
- preconditions_js_1.Preconditions.checkArgument(!!info.privateKey, 'privateKey', 'Private key is required');
160
- preconditions_js_1.Preconditions.checkArgument(!!info.chainCode, 'chainCode', 'Chain code is required');
158
+ preconditions_1.Preconditions.checkArgument(!!info.network, 'network', 'Network is required');
159
+ preconditions_1.Preconditions.checkArgument(!!info.privateKey, 'privateKey', 'Private key is required');
160
+ preconditions_1.Preconditions.checkArgument(!!info.chainCode, 'chainCode', 'Chain code is required');
161
161
  const buffers = {
162
- version: Buffer.alloc(4),
163
- depth: Buffer.from([info.depth || 0]),
164
- parentFingerPrint: info.parentFingerPrint || Buffer.alloc(4),
165
- childIndex: Buffer.alloc(4),
162
+ version: util_1.BufferUtil.alloc(4),
163
+ depth: util_1.BufferUtil.from([info.depth || 0]),
164
+ parentFingerPrint: info.parentFingerPrint || util_1.BufferUtil.alloc(4),
165
+ childIndex: util_1.BufferUtil.alloc(4),
166
166
  chainCode: info.chainCode,
167
167
  privateKey: info.privateKey.toBuffer(),
168
168
  checksum: undefined,
@@ -171,31 +171,31 @@ class HDPrivateKey {
171
171
  buffers.childIndex.writeUInt32BE(info.childIndex || 0, 0);
172
172
  const version = info.network.xprivkey;
173
173
  const depth = info.depth || 0;
174
- const parentFingerPrint = info.parentFingerPrint || Buffer.alloc(4);
174
+ const parentFingerPrint = info.parentFingerPrint || util_1.BufferUtil.alloc(4);
175
175
  const childIndex = info.childIndex || 0;
176
176
  const chainCode = info.chainCode;
177
177
  const privateKeyBuffer = info.privateKey.toBuffer();
178
- const buf = Buffer.alloc(78);
178
+ const buf = util_1.BufferUtil.alloc(78);
179
179
  buf.writeUInt32BE(version, 0);
180
180
  buf.writeUInt8(depth, 4);
181
181
  parentFingerPrint.copy(buf, 5);
182
182
  buf.writeUInt32BE(childIndex, 9);
183
183
  chainCode.copy(buf, 13);
184
184
  privateKeyBuffer.copy(buf, 46);
185
- const xprivkey = base58check_js_1.Base58Check.encode(buf);
186
- js_js_1.JSUtil.defineImmutable(this, {
185
+ const xprivkey = base58check_1.Base58Check.encode(buf);
186
+ util_1.JSUtil.defineImmutable(this, {
187
187
  network: info.network,
188
188
  depth: info.depth || 0,
189
- parentFingerPrint: info.parentFingerPrint || Buffer.alloc(4),
189
+ parentFingerPrint: info.parentFingerPrint || util_1.BufferUtil.alloc(4),
190
190
  childIndex: info.childIndex || 0,
191
191
  chainCode: info.chainCode,
192
192
  privateKey: info.privateKey,
193
- publicKey: publickey_js_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true),
194
- fingerPrint: hash_js_1.Hash.sha256ripemd160(publickey_js_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true).toBuffer()).subarray(0, 4),
193
+ publicKey: publickey_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true),
194
+ fingerPrint: hash_1.Hash.sha256ripemd160(publickey_1.PublicKey.fromPoint(info.privateKey.toPublicKey().point, true).toBuffer()).slice(0, 4),
195
195
  xprivkey: xprivkey,
196
196
  _buffers: buffers,
197
197
  });
198
- this._hdPublicKey = new hdpublickey_js_1.HDPublicKey({
198
+ this._hdPublicKey = new hdpublickey_1.HDPublicKey({
199
199
  network: this.network,
200
200
  depth: this.depth,
201
201
  parentFingerPrint: this.parentFingerPrint,
@@ -282,7 +282,7 @@ class HDPrivateKey {
282
282
  if (index < HDPrivateKey.Hardened && hardened === true) {
283
283
  index += HDPrivateKey.Hardened;
284
284
  }
285
- const indexBuffer = Buffer.from([
285
+ const indexBuffer = util_1.BufferUtil.from([
286
286
  index >> 24,
287
287
  index >> 16,
288
288
  index >> 8,
@@ -291,32 +291,40 @@ class HDPrivateKey {
291
291
  let data;
292
292
  if (hardened && nonCompliant) {
293
293
  const nonZeroPadded = this.privateKey.bn.toBuffer();
294
- data = Buffer.concat([Buffer.from([0]), nonZeroPadded, indexBuffer]);
294
+ data = util_1.BufferUtil.concat([
295
+ util_1.BufferUtil.from([0]),
296
+ nonZeroPadded,
297
+ indexBuffer,
298
+ ]);
295
299
  }
296
300
  else if (hardened) {
297
301
  const privateKeyBuffer = this.privateKey.bn.toBuffer({ size: 32 });
298
- data = Buffer.concat([Buffer.from([0]), privateKeyBuffer, indexBuffer]);
302
+ data = util_1.BufferUtil.concat([
303
+ util_1.BufferUtil.from([0]),
304
+ privateKeyBuffer,
305
+ indexBuffer,
306
+ ]);
299
307
  }
300
308
  else {
301
- data = Buffer.concat([this.publicKey.toBuffer(), indexBuffer]);
309
+ data = util_1.BufferUtil.concat([this.publicKey.toBuffer(), indexBuffer]);
302
310
  }
303
- const hash = hash_js_1.Hash.sha512hmac(data, this.chainCode);
304
- const leftPart = bn_js_1.BN.fromBuffer(hash.subarray(0, 32), { size: 32 });
305
- const childChainCode = hash.subarray(32, 64);
311
+ const hash = hash_1.Hash.sha512hmac(data, this.chainCode);
312
+ const leftPart = bn_1.BN.fromBuffer(hash.slice(0, 32), { size: 32 });
313
+ const childChainCode = hash.slice(32, 64);
306
314
  const childPrivateKey = leftPart
307
315
  .add(this.privateKey.toBigNumber())
308
- .umod(point_js_1.Point.getN())
316
+ .umod(point_1.Point.getN())
309
317
  .toBuffer({ size: 32 });
310
- if (!privatekey_js_1.PrivateKey.isValid(childPrivateKey)) {
318
+ if (!privatekey_1.PrivateKey.isValid(childPrivateKey)) {
311
319
  return this._deriveWithNumber(index + 1, undefined, nonCompliant);
312
320
  }
313
321
  return new HDPrivateKey({
314
322
  network: this.network,
315
323
  depth: this.depth + 1,
316
- parentFingerPrint: hash_js_1.Hash.sha256ripemd160(this.privateKey.toPublicKey().toBuffer()).subarray(0, 4),
324
+ parentFingerPrint: hash_1.Hash.sha256ripemd160(this.privateKey.toPublicKey().toBuffer()).slice(0, 4),
317
325
  childIndex: index,
318
326
  chainCode: childChainCode,
319
- privateKey: new privatekey_js_1.PrivateKey({
327
+ privateKey: new privatekey_1.PrivateKey({
320
328
  bn: childPrivateKey.toString('hex'),
321
329
  network: this.network.name,
322
330
  compressed: this.privateKey.compressed,
@@ -372,7 +380,7 @@ class HDPrivateKey {
372
380
  const childIndex = this.childIndex;
373
381
  const chainCode = this.chainCode;
374
382
  const privateKeyBuffer = this.privateKey.toBuffer();
375
- const buf = Buffer.alloc(78);
383
+ const buf = util_1.BufferUtil.alloc(78);
376
384
  buf.writeUInt32BE(version, 0);
377
385
  buf.writeUInt8(depth, 4);
378
386
  parentFingerPrint.copy(buf, 5);
@@ -392,11 +400,11 @@ class HDPrivateKey {
392
400
  return new HDPrivateKey(obj);
393
401
  }
394
402
  static fromSeed(hexa, network) {
395
- const seed = typeof hexa === 'string' ? Buffer.from(hexa, 'hex') : hexa;
403
+ const seed = typeof hexa === 'string' ? util_1.BufferUtil.from(hexa, 'hex') : hexa;
396
404
  return new HDPrivateKey(HDPrivateKey._fromSeed(seed, network));
397
405
  }
398
406
  static fromRandom(network) {
399
- const resolvedNetwork = network ? (0, networks_js_1.get)(network) : undefined;
407
+ const resolvedNetwork = network ? (0, networks_1.get)(network) : undefined;
400
408
  return new HDPrivateKey(HDPrivateKey._getRandomData(resolvedNetwork));
401
409
  }
402
410
  inspect() {