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,31 +1,32 @@
1
- import { PublicKey } from '../publickey.js';
2
- import { Point } from './point.js';
3
- import { BN } from './bn.js';
4
- import { Hash } from './hash.js';
5
- import { Signature } from './signature.js';
6
- export const MUSIG_TAG_KEYSORT = 'KeyAgg list';
7
- export const MUSIG_TAG_KEYAGG_COEFF = 'KeyAgg coefficient';
8
- export const MUSIG_TAG_NONCE_COEFF = 'MuSig/noncecoef';
9
- const MUSIG_TAG_AUX = 'MuSig/aux';
10
- export const MUSIG_TAG_NONCE = 'MuSig/nonce';
11
- export function musigTaggedHash(tag, data) {
12
- const tagHash = Hash.sha256(Buffer.from(tag, 'utf8'));
13
- const combined = Buffer.concat([tagHash, tagHash, data]);
1
+ import { PublicKey } from '../publickey';
2
+ import { Point } from './point';
3
+ import { BN } from './bn';
4
+ import { Hash } from './hash';
5
+ import { Signature } from './signature';
6
+ import { BufferUtil } from '../util';
7
+ export const MUSIG2_TAG_KEYSORT = 'KeyAgg list';
8
+ export const MUSIG2_TAG_KEYAGG_COEFF = 'KeyAgg coefficient';
9
+ export const MUSIG2_TAG_NONCE_COEFF = 'MuSig/noncecoef';
10
+ export const MUSIG2_TAG_AUX = 'MuSig/aux';
11
+ export const MUSIG2_TAG_NONCE = 'MuSig/nonce';
12
+ export function muSig2TaggedHash(tag, data) {
13
+ const tagHash = Hash.sha256(BufferUtil.from(tag, 'utf8'));
14
+ const combined = BufferUtil.concat([tagHash, tagHash, data]);
14
15
  return Hash.sha256(combined);
15
16
  }
16
17
  function hashKeys(pubkeys) {
17
- const data = Buffer.concat(pubkeys.map(pk => pk.toBuffer()));
18
- return musigTaggedHash(MUSIG_TAG_KEYSORT, data);
18
+ const data = BufferUtil.concat(pubkeys.map(pk => pk.toBuffer()));
19
+ return muSig2TaggedHash(MUSIG2_TAG_KEYSORT, data);
19
20
  }
20
21
  function keyAggCoeff(L, pubkey, isSecondKey, equalsFirstKey) {
21
22
  if (isSecondKey && equalsFirstKey) {
22
- return new BN(1);
23
+ return BN.One;
23
24
  }
24
- const data = Buffer.concat([L, pubkey.toBuffer()]);
25
- const hash = musigTaggedHash(MUSIG_TAG_KEYAGG_COEFF, data);
26
- return new BN(hash, 'be');
25
+ const data = BufferUtil.concat([L, pubkey.toBuffer()]);
26
+ const hash = muSig2TaggedHash(MUSIG2_TAG_KEYAGG_COEFF, data);
27
+ return BN.fromBuffer(hash);
27
28
  }
28
- export function musigKeyAgg(pubkeys) {
29
+ export function muSig2KeyAgg(pubkeys) {
29
30
  if (pubkeys.length === 0) {
30
31
  throw new Error('Cannot aggregate zero public keys');
31
32
  }
@@ -46,13 +47,13 @@ export function musigKeyAgg(pubkeys) {
46
47
  const isSecond = i === 1;
47
48
  const equalsFirst = sortedPubkeys[i].toString() === firstKey.toString();
48
49
  const coeff = keyAggCoeff(L, sortedPubkeys[i], isSecond, equalsFirst);
49
- keyAggCoeffMap.set(i, coeff);
50
+ keyAggCoeffMap.set(sortedPubkeys[i].toString(), coeff);
50
51
  }
51
52
  let Q = null;
52
53
  const n = Point.getN();
53
54
  for (let i = 0; i < sortedPubkeys.length; i++) {
54
- const coeff = keyAggCoeffMap.get(i);
55
55
  const pk = sortedPubkeys[i];
56
+ const coeff = keyAggCoeffMap.get(pk.toString());
56
57
  const term = pk.point.mul(coeff.umod(n));
57
58
  if (Q === null) {
58
59
  Q = term;
@@ -75,25 +76,25 @@ export function musigKeyAgg(pubkeys) {
75
76
  aggregatedPubKey,
76
77
  };
77
78
  }
78
- export function musigNonceGen(privateKey, aggregatedPubKey, message, extraInput) {
79
+ export function muSig2NonceGen(privateKey, aggregatedPubKey, message, extraInput) {
79
80
  const G = Point.getG();
80
81
  const n = Point.getN();
81
- const sessionData = Buffer.concat([
82
- privateKey.bn.toArrayLike(Buffer, 'be', 32),
82
+ const sessionData = BufferUtil.concat([
83
+ privateKey.bn.toBuffer({ size: 32 }),
83
84
  aggregatedPubKey.toBuffer(),
84
- message || Buffer.alloc(32),
85
- extraInput || Buffer.alloc(32),
85
+ message || BufferUtil.alloc(32),
86
+ extraInput || BufferUtil.alloc(32),
86
87
  ]);
87
- const auxHash = musigTaggedHash(MUSIG_TAG_AUX, sessionData);
88
- const rand1 = musigTaggedHash(MUSIG_TAG_NONCE, Buffer.concat([auxHash, Buffer.from([0x01])]));
89
- const rand2 = musigTaggedHash(MUSIG_TAG_NONCE, Buffer.concat([auxHash, Buffer.from([0x02])]));
90
- let k1 = new BN(rand1, 'be').umod(n);
91
- let k2 = new BN(rand2, 'be').umod(n);
88
+ const auxHash = muSig2TaggedHash(MUSIG2_TAG_AUX, sessionData);
89
+ const rand1 = muSig2TaggedHash(MUSIG2_TAG_NONCE, BufferUtil.concat([auxHash, BufferUtil.from([0x01])]));
90
+ const rand2 = muSig2TaggedHash(MUSIG2_TAG_NONCE, BufferUtil.concat([auxHash, BufferUtil.from([0x02])]));
91
+ let k1 = BN.fromBuffer(rand1).umod(n);
92
+ let k2 = BN.fromBuffer(rand2).umod(n);
92
93
  if (k1.isZero()) {
93
- k1 = new BN(1);
94
+ k1 = BN.One;
94
95
  }
95
96
  if (k2.isZero()) {
96
- k2 = new BN(1);
97
+ k2 = BN.One;
97
98
  }
98
99
  const R1 = G.mul(k1);
99
100
  const R2 = G.mul(k2);
@@ -104,7 +105,7 @@ export function musigNonceGen(privateKey, aggregatedPubKey, message, extraInput)
104
105
  publicNonces: [R1, R2],
105
106
  };
106
107
  }
107
- export function musigNonceAgg(publicNonces) {
108
+ export function muSig2NonceAgg(publicNonces) {
108
109
  if (publicNonces.length === 0) {
109
110
  throw new Error('Cannot aggregate zero nonces');
110
111
  }
@@ -130,65 +131,67 @@ export function musigNonceAgg(publicNonces) {
130
131
  R2: R2_agg,
131
132
  };
132
133
  }
133
- export function musigPartialSign(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
134
+ export function muSig2PartialSign(secretNonce, privateKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
134
135
  const n = Point.getN();
135
136
  const [k1, k2] = secretNonce.secretNonces;
136
137
  const { R1, R2 } = aggregatedNonce;
137
138
  const Q = keyAggContext.aggregatedPubKey;
138
- const nonceCoefData = Buffer.concat([
139
+ const nonceCoefData = BufferUtil.concat([
139
140
  Q.toBuffer(),
140
141
  Point.pointToCompressed(R1),
141
142
  Point.pointToCompressed(R2),
142
143
  message,
143
144
  ]);
144
- const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
145
+ const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
145
146
  let k = k1.add(b.mul(k2)).umod(n);
146
147
  const R = R1.add(R2.mul(b));
147
148
  if (!R.hasSquare()) {
148
149
  k = n.sub(k).umod(n);
149
150
  }
150
- const R_x = R.getX().toArrayLike(Buffer, 'be', 32);
151
+ const R_x = R.x.toBuffer({ size: 32 });
151
152
  const keyForChallenge = publicKeyForChallenge || Q;
152
153
  const Q_compressed = Point.pointToCompressed(keyForChallenge.point);
153
- const challengeData = Buffer.concat([R_x, Q_compressed, message]);
154
- const e = new BN(Hash.sha256(challengeData), 'be').umod(n);
155
- const a = keyAggContext.keyAggCoeff.get(signerIndex);
154
+ const challengeData = BufferUtil.concat([R_x, Q_compressed, message]);
155
+ const e = BN.fromBuffer(Hash.sha256(challengeData)).umod(n);
156
+ const signerPubKey = privateKey.publicKey.toString();
157
+ const a = keyAggContext.keyAggCoeff.get(signerPubKey);
156
158
  if (!a) {
157
- throw new Error(`Invalid signer index: ${signerIndex}`);
159
+ throw new Error(`Public key not found in key aggregation context: ${signerPubKey.slice(0, 20)}...`);
158
160
  }
159
161
  const x = privateKey.bn;
160
162
  const s = k.add(e.mul(a).mul(x)).umod(n);
161
163
  return s;
162
164
  }
163
- export function musigPartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
165
+ export function muSig2PartialSigVerify(partialSig, publicNonce, publicKey, keyAggContext, signerIndex, aggregatedNonce, message, publicKeyForChallenge) {
164
166
  try {
165
167
  const G = Point.getG();
166
168
  const n = Point.getN();
167
169
  const [R1_i, R2_i] = publicNonce;
168
170
  const { R1, R2 } = aggregatedNonce;
169
171
  const Q = keyAggContext.aggregatedPubKey;
170
- const nonceCoefData = Buffer.concat([
172
+ const nonceCoefData = BufferUtil.concat([
171
173
  Q.toBuffer(),
172
174
  Point.pointToCompressed(R1),
173
175
  Point.pointToCompressed(R2),
174
176
  message,
175
177
  ]);
176
- const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
178
+ const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
177
179
  const R_i = R1_i.add(R2_i.mul(b));
178
180
  const R = R1.add(R2.mul(b));
179
181
  const negated = !R.hasSquare();
180
- const R_x = R.getX().toArrayLike(Buffer, 'be', 32);
182
+ const R_x = R.x.toBuffer({ size: 32 });
181
183
  const keyForChallenge = publicKeyForChallenge || Q;
182
184
  const Q_compressed = Point.pointToCompressed(keyForChallenge.point);
183
- const challengeData = Buffer.concat([R_x, Q_compressed, message]);
184
- const e = new BN(Hash.sha256(challengeData), 'be').umod(n);
185
- const a = keyAggContext.keyAggCoeff.get(signerIndex);
185
+ const challengeData = BufferUtil.concat([R_x, Q_compressed, message]);
186
+ const e = BN.fromBuffer(Hash.sha256(challengeData)).umod(n);
187
+ const signerPubKeyStr = publicKey.toString();
188
+ const a = keyAggContext.keyAggCoeff.get(signerPubKeyStr);
186
189
  if (!a) {
187
- throw new Error(`Invalid signer index: ${signerIndex}`);
190
+ throw new Error(`Public key not found in key aggregation context: ${signerPubKeyStr.slice(0, 20)}...`);
188
191
  }
189
192
  const lhs = G.mul(partialSig.umod(n));
190
193
  const eaP = publicKey.point.mul(e.mul(a).umod(n));
191
- const R_i_adjusted = negated ? R_i.mul(n.sub(new BN(1))) : R_i;
194
+ const R_i_adjusted = negated ? R_i.mul(n.sub(BN.One)) : R_i;
192
195
  const rhs = R_i_adjusted.add(eaP);
193
196
  return lhs.eq(rhs);
194
197
  }
@@ -196,29 +199,29 @@ export function musigPartialSigVerify(partialSig, publicNonce, publicKey, keyAgg
196
199
  return false;
197
200
  }
198
201
  }
199
- export function musigSigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, sighashType, publicKeyForNonceCoef) {
202
+ export function muSig2SigAgg(partialSigs, aggregatedNonce, message, aggregatedPubKey, sighashType, publicKeyForNonceCoef) {
200
203
  if (partialSigs.length === 0) {
201
204
  throw new Error('Cannot aggregate zero partial signatures');
202
205
  }
203
206
  const n = Point.getN();
204
207
  const { R1, R2 } = aggregatedNonce;
205
208
  const keyForNonceCoef = publicKeyForNonceCoef || aggregatedPubKey;
206
- const nonceCoefData = Buffer.concat([
209
+ const nonceCoefData = BufferUtil.concat([
207
210
  keyForNonceCoef.toBuffer(),
208
211
  Point.pointToCompressed(R1),
209
212
  Point.pointToCompressed(R2),
210
213
  message,
211
214
  ]);
212
- const b = new BN(musigTaggedHash(MUSIG_TAG_NONCE_COEFF, nonceCoefData), 'be');
215
+ const b = BN.fromBuffer(muSig2TaggedHash(MUSIG2_TAG_NONCE_COEFF, nonceCoefData));
213
216
  const R = R1.add(R2.mul(b));
214
- let s = new BN(0);
217
+ let s = BN.Zero;
215
218
  for (const partialSig of partialSigs) {
216
219
  s = s.add(partialSig).umod(n);
217
220
  }
218
221
  if (s.isZero()) {
219
222
  throw new Error('Aggregated signature s is zero (invalid)');
220
223
  }
221
- const r = R.getX();
224
+ const r = R.x;
222
225
  const signature = new Signature({
223
226
  r: r,
224
227
  s: s,
@@ -228,12 +231,3 @@ export function musigSigAgg(partialSigs, aggregatedNonce, message, aggregatedPub
228
231
  });
229
232
  return signature;
230
233
  }
231
- export default {
232
- musigKeyAgg,
233
- musigNonceGen,
234
- musigNonceAgg,
235
- musigPartialSign,
236
- musigPartialSigVerify,
237
- musigSigAgg,
238
- musigTaggedHash,
239
- };
@@ -1,10 +1,15 @@
1
1
  import elliptic from 'elliptic';
2
- import { BN } from './bn.js';
2
+ import { BN } from './bn';
3
+ import { BufferUtil } from '../util';
3
4
  const ecInstance = new elliptic.ec('secp256k1');
4
5
  const ecPoint = ecInstance.curve.point.bind(ecInstance.curve);
5
6
  const ecPointFromX = ecInstance.curve.pointFromX.bind(ecInstance.curve);
7
+ export const PREFIX_Y_ODD = 0x03;
8
+ export const PREFIX_Y_EVEN = 0x02;
6
9
  export class Point {
7
10
  _point;
11
+ static PrefixOddY = BufferUtil.from([PREFIX_Y_ODD]);
12
+ static PrefixEvenY = BufferUtil.from([PREFIX_Y_EVEN]);
8
13
  constructor(x, y, isRed) {
9
14
  try {
10
15
  const bnX = x instanceof BN ? x.bn : new BN(x);
@@ -16,6 +21,14 @@ export class Point {
16
21
  }
17
22
  this.validate();
18
23
  }
24
+ get x() {
25
+ const xBuffer = this._point.getX().toBuffer();
26
+ return BN.fromString(xBuffer.toString('hex'), 'hex');
27
+ }
28
+ get y() {
29
+ const yBuffer = this._point.getY().toBuffer();
30
+ return BN.fromString(yBuffer.toString('hex'), 'hex');
31
+ }
19
32
  static fromX(odd, x) {
20
33
  try {
21
34
  const xStr = typeof x === 'string' ? x : x.toString();
@@ -53,19 +66,13 @@ export class Point {
53
66
  static getN() {
54
67
  return new BN(ecInstance.curve.n.toArray());
55
68
  }
56
- getX() {
57
- return new BN(this._point.getX().toString());
58
- }
59
- getY() {
60
- return new BN(this._point.getY().toString());
61
- }
62
69
  validate() {
63
70
  if (this.isInfinity()) {
64
71
  throw new Error('Point cannot be equal to Infinity');
65
72
  }
66
73
  try {
67
- const x = this.getX();
68
- const y = this.getY();
74
+ const x = this.x;
75
+ const y = this.y;
69
76
  if (x === undefined || y === undefined) {
70
77
  throw new Error('Point coordinates are undefined');
71
78
  }
@@ -104,18 +111,18 @@ export class Point {
104
111
  return this._point.eq(other._point);
105
112
  }
106
113
  static pointToCompressed(point) {
107
- const xbuf = point.getX().toArrayLike(Buffer, 'be', 32);
108
- const y = point.getY();
114
+ const xbuf = point.x.toBuffer({ size: 32 });
115
+ const y = point.y;
109
116
  const odd = y.mod(new BN(2)).isOdd();
110
- const prefix = odd ? Buffer.from([0x03]) : Buffer.from([0x02]);
111
- return Buffer.concat([prefix, xbuf]);
117
+ const prefix = odd ? Point.PrefixOddY : Point.PrefixEvenY;
118
+ return BufferUtil.concat([prefix, xbuf]);
112
119
  }
113
120
  hasSquare() {
114
121
  if (this.isInfinity()) {
115
122
  return false;
116
123
  }
117
- const x = this.getX();
118
- const y = this.getY();
124
+ const x = this.x;
125
+ const y = this.y;
119
126
  const p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
120
127
  const x3 = x.mul(x).mod(p).mul(x).mod(p);
121
128
  const c = x3.add(new BN(7)).mod(p);
@@ -1,7 +1,8 @@
1
1
  import { randomBytes as nobleRandomBytes } from '@noble/hashes/utils';
2
+ import { BufferUtil } from '../util';
2
3
  export class Random {
3
4
  static getRandomBuffer(size) {
4
- return Buffer.from(nobleRandomBytes(size));
5
+ return BufferUtil.from(nobleRandomBytes(size));
5
6
  }
6
7
  static getRandomBufferNode(size) {
7
8
  return Random.getRandomBuffer(size);
@@ -11,7 +12,7 @@ export class Random {
11
12
  }
12
13
  static getPseudoRandomBuffer(size) {
13
14
  const b32 = 0x100000000;
14
- const b = Buffer.alloc(size);
15
+ const b = BufferUtil.alloc(size);
15
16
  let r = 0;
16
17
  for (let i = 0; i <= size; i++) {
17
18
  const j = Math.floor(i / 4);
@@ -1,7 +1,8 @@
1
- import { BN } from './bn.js';
2
- import { Point } from './point.js';
3
- import { Signature } from './signature.js';
4
- import { Hash } from './hash.js';
1
+ import { BN } from './bn';
2
+ import { Point } from './point';
3
+ import { Signature } from './signature';
4
+ import { Hash } from './hash';
5
+ import { BufferUtil } from '../util';
5
6
  export class Schnorr {
6
7
  hashbuf;
7
8
  endian;
@@ -38,10 +39,10 @@ export class Schnorr {
38
39
  if (!hashbuf || !privkey || !d) {
39
40
  throw new Error('invalid parameters');
40
41
  }
41
- if (!Buffer.isBuffer(hashbuf) || hashbuf.length !== 32) {
42
+ if (!BufferUtil.isBuffer(hashbuf) || hashbuf.length !== 32) {
42
43
  throw new Error('hashbuf must be a 32 byte buffer');
43
44
  }
44
- const e = new BN(hashbuf, 'be');
45
+ const e = BN.fromBuffer(hashbuf);
45
46
  const obj = this._findSignature(d, e);
46
47
  obj.compressed = this.pubkey.compressed;
47
48
  obj.isSchnorr = true;
@@ -51,13 +52,13 @@ export class Schnorr {
51
52
  _findSignature(d, e) {
52
53
  const n = Point.getN();
53
54
  const G = Point.getG();
54
- if (d.lte(new BN(0))) {
55
+ if (d.lte(BN.Zero)) {
55
56
  throw new Error('privkey out of field of curve');
56
57
  }
57
58
  if (d.gte(n)) {
58
59
  throw new Error('privkey out of field of curve');
59
60
  }
60
- let k = this.nonceFunctionRFC6979(d.toArrayLike(Buffer, 'be', 32), e.toArrayLike(Buffer, 'be', 32));
61
+ let k = this.nonceFunctionRFC6979(d.toBuffer({ size: 32 }), e.toBuffer({ size: 32 }));
61
62
  const P = G.mul(d);
62
63
  const R = G.mul(k);
63
64
  if (R.hasSquare()) {
@@ -65,36 +66,26 @@ export class Schnorr {
65
66
  else {
66
67
  k = n.sub(k);
67
68
  }
68
- const r = R.getX();
69
+ const r = R.x;
69
70
  const rBuffer = this.getrBuffer(r);
70
- const e0 = new BN(Hash.sha256(Buffer.concat([
71
+ const e0 = BN.fromBuffer(Hash.sha256(BufferUtil.concat([
71
72
  rBuffer,
72
73
  Point.pointToCompressed(P),
73
- e.toArrayLike(Buffer, 'be', 32),
74
- ])), 'be');
74
+ e.toBuffer({ size: 32 }),
75
+ ])));
75
76
  const s = e0.mul(d).add(k).mod(n);
76
77
  return { r, s, compressed: this.pubkey.compressed, isSchnorr: true };
77
78
  }
78
79
  getrBuffer(r) {
79
- const rNaturalLength = r.toArrayLike(Buffer, 'be').length;
80
- if (rNaturalLength < 32) {
81
- return r.toArrayLike(Buffer, 'be', 32);
82
- }
83
- return r.toArrayLike(Buffer, 'be');
80
+ const buf = r.toBuffer();
81
+ return buf.length < 32 ? r.toBuffer({ size: 32 }) : buf;
84
82
  }
85
83
  getsBuffer(s) {
86
- const sNaturalLength = s.toArrayLike(Buffer, 'be').length;
87
- if (sNaturalLength < 32) {
88
- return s.toArrayLike(Buffer, 'be', 32);
89
- }
90
- return s.toArrayLike(Buffer, 'be');
84
+ const buf = s.toBuffer();
85
+ return buf.length < 32 ? s.toBuffer({ size: 32 }) : buf;
91
86
  }
92
87
  sigError() {
93
- if (!Buffer.isBuffer(this.hashbuf) || this.hashbuf.length !== 32) {
94
- return true;
95
- }
96
- const sigLength = this.getrBuffer(this.sig.r).length + this.getsBuffer(this.sig.s).length;
97
- if (!(sigLength === 64 || sigLength === 65)) {
88
+ if (!BufferUtil.isBuffer(this.hashbuf) || this.hashbuf.length !== 32) {
98
89
  return true;
99
90
  }
100
91
  const hashbuf = this.endian === 'little' ? this.reverseBuffer(this.hashbuf) : this.hashbuf;
@@ -105,53 +96,53 @@ export class Schnorr {
105
96
  }
106
97
  const r = this.sig.r;
107
98
  const s = this.sig.s;
108
- const p = new BN('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 16);
99
+ const p = BN.fromString('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F', 'hex');
109
100
  const n = Point.getN();
110
101
  if (r.gte(p) || s.gte(n)) {
111
102
  return true;
112
103
  }
113
104
  const Br = this.getrBuffer(this.sig.r);
114
105
  const Bp = Point.pointToCompressed(P);
115
- const hash = Hash.sha256(Buffer.concat([Br, Bp, hashbuf]));
116
- const e = new BN(hash, 'be').mod(n);
106
+ const hash = Hash.sha256(BufferUtil.concat([Br, Bp, hashbuf]));
107
+ const e = BN.fromBuffer(hash).mod(n);
117
108
  const sG = G.mul(s);
118
109
  const eP = P.mul(n.sub(e));
119
110
  const R = sG.add(eP);
120
- if (R.isInfinity() || !R.hasSquare() || !R.getX().eq(r)) {
111
+ if (R.isInfinity() || !R.hasSquare() || !R.x.eq(r)) {
121
112
  return true;
122
113
  }
123
114
  return false;
124
115
  }
125
116
  verify() {
126
- this.verified = !!!this.sigError();
117
+ this.verified = this.sigError() === false;
127
118
  return this;
128
119
  }
129
120
  nonceFunctionRFC6979(privkey, msgbuf) {
130
- let V = Buffer.from('0101010101010101010101010101010101010101010101010101010101010101', 'hex');
131
- let K = Buffer.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
132
- const blob = Buffer.concat([
121
+ let V = BufferUtil.from('0101010101010101010101010101010101010101010101010101010101010101', 'hex');
122
+ let K = BufferUtil.from('0000000000000000000000000000000000000000000000000000000000000000', 'hex');
123
+ const blob = BufferUtil.concat([
133
124
  privkey,
134
125
  msgbuf,
135
- Buffer.from('', 'ascii'),
136
- Buffer.from('Schnorr+SHA256 ', 'ascii'),
126
+ BufferUtil.from('', 'ascii'),
127
+ BufferUtil.from('Schnorr+SHA256 ', 'ascii'),
137
128
  ]);
138
- K = Hash.sha256hmac(Buffer.concat([V, Buffer.from('00', 'hex'), blob]), K);
129
+ K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('00', 'hex'), blob]), K);
139
130
  V = Hash.sha256hmac(V, K);
140
- K = Hash.sha256hmac(Buffer.concat([V, Buffer.from('01', 'hex'), blob]), K);
131
+ K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('01', 'hex'), blob]), K);
141
132
  V = Hash.sha256hmac(V, K);
142
- let k = new BN(0);
133
+ let k = BN.Zero;
143
134
  let T;
144
135
  while (true) {
145
136
  V = Hash.sha256hmac(V, K);
146
- T = new BN(V, 'be');
137
+ T = BN.fromBuffer(V);
147
138
  k = T;
148
139
  if (V.length < 32) {
149
140
  throw new Error('V length should be >= 32');
150
141
  }
151
- if (k.gt(new BN(0)) && k.lt(Point.getN())) {
142
+ if (k.gt(BN.Zero) && k.lt(Point.getN())) {
152
143
  break;
153
144
  }
154
- K = Hash.sha256hmac(Buffer.concat([V, Buffer.from('00', 'hex')]), K);
145
+ K = Hash.sha256hmac(BufferUtil.concat([V, BufferUtil.from('00', 'hex')]), K);
155
146
  V = Hash.sha256hmac(V, K);
156
147
  }
157
148
  return k;
@@ -176,7 +167,7 @@ export class Schnorr {
176
167
  .verify().verified;
177
168
  }
178
169
  reverseBuffer(buf) {
179
- const buf2 = Buffer.alloc(buf.length);
170
+ const buf2 = BufferUtil.alloc(buf.length);
180
171
  for (let i = 0; i < buf.length; i++) {
181
172
  buf2[i] = buf[buf.length - 1 - i];
182
173
  }