@bsv/sdk 1.0.29 → 1.0.32

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 (329) hide show
  1. package/dist/cjs/mod.js +25 -0
  2. package/dist/cjs/mod.js.map +1 -0
  3. package/dist/cjs/package.json +49 -0
  4. package/dist/cjs/src/compat/BSM.js +77 -0
  5. package/dist/cjs/src/compat/BSM.js.map +1 -0
  6. package/dist/cjs/src/compat/ECIES.js +512 -0
  7. package/dist/cjs/src/compat/ECIES.js.map +1 -0
  8. package/dist/cjs/src/compat/HD.js +344 -0
  9. package/dist/cjs/src/compat/HD.js.map +1 -0
  10. package/dist/cjs/src/compat/Mnemonic.js +298 -0
  11. package/dist/cjs/src/compat/Mnemonic.js.map +1 -0
  12. package/dist/cjs/src/compat/bip-39-wordlist-en.js +2057 -0
  13. package/dist/cjs/src/compat/bip-39-wordlist-en.js.map +1 -0
  14. package/dist/cjs/src/compat/index.js +37 -0
  15. package/dist/cjs/src/compat/index.js.map +1 -0
  16. package/dist/cjs/src/messages/EncryptedMessage.js +69 -0
  17. package/dist/cjs/src/messages/EncryptedMessage.js.map +1 -0
  18. package/dist/cjs/src/messages/SignedMessage.js +85 -0
  19. package/dist/cjs/src/messages/SignedMessage.js.map +1 -0
  20. package/dist/cjs/src/messages/index.js +29 -0
  21. package/dist/cjs/src/messages/index.js.map +1 -0
  22. package/dist/cjs/src/primitives/AESGCM.js +384 -0
  23. package/dist/cjs/src/primitives/AESGCM.js.map +1 -0
  24. package/dist/cjs/src/primitives/BasePoint.js +19 -0
  25. package/dist/cjs/src/primitives/BasePoint.js.map +1 -0
  26. package/dist/cjs/src/primitives/BigNumber.js +4272 -0
  27. package/dist/cjs/src/primitives/BigNumber.js.map +1 -0
  28. package/dist/cjs/src/primitives/Curve.js +1126 -0
  29. package/dist/cjs/src/primitives/Curve.js.map +1 -0
  30. package/dist/cjs/src/primitives/DRBG.js +99 -0
  31. package/dist/cjs/src/primitives/DRBG.js.map +1 -0
  32. package/dist/cjs/src/primitives/ECDSA.js +169 -0
  33. package/dist/cjs/src/primitives/ECDSA.js.map +1 -0
  34. package/dist/cjs/src/primitives/Hash.js +1387 -0
  35. package/dist/cjs/src/primitives/Hash.js.map +1 -0
  36. package/dist/cjs/src/primitives/JacobianPoint.js +400 -0
  37. package/dist/cjs/src/primitives/JacobianPoint.js.map +1 -0
  38. package/dist/cjs/src/primitives/K256.js +111 -0
  39. package/dist/cjs/src/primitives/K256.js.map +1 -0
  40. package/dist/cjs/src/primitives/Mersenne.js +118 -0
  41. package/dist/cjs/src/primitives/Mersenne.js.map +1 -0
  42. package/dist/cjs/src/primitives/MontgomoryMethod.js +150 -0
  43. package/dist/cjs/src/primitives/MontgomoryMethod.js.map +1 -0
  44. package/dist/cjs/src/primitives/Point.js +819 -0
  45. package/dist/cjs/src/primitives/Point.js.map +1 -0
  46. package/dist/cjs/src/primitives/PrivateKey.js +246 -0
  47. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -0
  48. package/dist/cjs/src/primitives/PublicKey.js +168 -0
  49. package/dist/cjs/src/primitives/PublicKey.js.map +1 -0
  50. package/dist/cjs/src/primitives/Random.js +57 -0
  51. package/dist/cjs/src/primitives/Random.js.map +1 -0
  52. package/dist/cjs/src/primitives/ReductionContext.js +490 -0
  53. package/dist/cjs/src/primitives/ReductionContext.js.map +1 -0
  54. package/dist/cjs/src/primitives/Signature.js +357 -0
  55. package/dist/cjs/src/primitives/Signature.js.map +1 -0
  56. package/dist/cjs/src/primitives/SymmetricKey.js +82 -0
  57. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -0
  58. package/dist/cjs/src/primitives/TransactionSignature.js +172 -0
  59. package/dist/cjs/src/primitives/TransactionSignature.js.map +1 -0
  60. package/dist/cjs/src/primitives/index.js +51 -0
  61. package/dist/cjs/src/primitives/index.js.map +1 -0
  62. package/dist/cjs/src/primitives/utils.js +624 -0
  63. package/dist/cjs/src/primitives/utils.js.map +1 -0
  64. package/dist/cjs/src/script/LockingScript.js +35 -0
  65. package/dist/cjs/src/script/LockingScript.js.map +1 -0
  66. package/dist/cjs/src/script/OP.js +207 -0
  67. package/dist/cjs/src/script/OP.js.map +1 -0
  68. package/dist/cjs/src/script/Script.js +435 -0
  69. package/dist/cjs/src/script/Script.js.map +1 -0
  70. package/dist/cjs/src/script/ScriptChunk.js +3 -0
  71. package/dist/cjs/src/script/ScriptChunk.js.map +1 -0
  72. package/dist/cjs/src/script/ScriptTemplate.js +3 -0
  73. package/dist/cjs/src/script/ScriptTemplate.js.map +1 -0
  74. package/dist/cjs/src/script/Spend.js +1252 -0
  75. package/dist/cjs/src/script/Spend.js.map +1 -0
  76. package/dist/cjs/src/script/UnlockingScript.js +35 -0
  77. package/dist/cjs/src/script/UnlockingScript.js.map +1 -0
  78. package/dist/cjs/src/script/index.js +32 -0
  79. package/dist/cjs/src/script/index.js.map +1 -0
  80. package/dist/cjs/src/script/templates/P2PKH.js +120 -0
  81. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -0
  82. package/dist/cjs/src/script/templates/RPuzzle.js +125 -0
  83. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -0
  84. package/dist/cjs/src/script/templates/index.js +11 -0
  85. package/dist/cjs/src/script/templates/index.js.map +1 -0
  86. package/dist/cjs/src/transaction/Broadcaster.js +3 -0
  87. package/dist/cjs/src/transaction/Broadcaster.js.map +1 -0
  88. package/dist/cjs/src/transaction/ChainTracker.js +3 -0
  89. package/dist/cjs/src/transaction/ChainTracker.js.map +1 -0
  90. package/dist/cjs/src/transaction/FeeModel.js +3 -0
  91. package/dist/cjs/src/transaction/FeeModel.js.map +1 -0
  92. package/dist/cjs/src/transaction/MerklePath.js +239 -0
  93. package/dist/cjs/src/transaction/MerklePath.js.map +1 -0
  94. package/dist/cjs/src/transaction/Transaction.js +616 -0
  95. package/dist/cjs/src/transaction/Transaction.js.map +1 -0
  96. package/dist/cjs/src/transaction/TransactionInput.js +3 -0
  97. package/dist/cjs/src/transaction/TransactionInput.js.map +1 -0
  98. package/dist/cjs/src/transaction/TransactionOutput.js +3 -0
  99. package/dist/cjs/src/transaction/TransactionOutput.js.map +1 -0
  100. package/dist/cjs/src/transaction/broadcasters/ARC.js +112 -0
  101. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -0
  102. package/dist/cjs/src/transaction/broadcasters/index.js +9 -0
  103. package/dist/cjs/src/transaction/broadcasters/index.js.map +1 -0
  104. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js +69 -0
  105. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  106. package/dist/cjs/src/transaction/fee-models/index.js +9 -0
  107. package/dist/cjs/src/transaction/fee-models/index.js.map +1 -0
  108. package/dist/cjs/src/transaction/index.js +11 -0
  109. package/dist/cjs/src/transaction/index.js.map +1 -0
  110. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  111. package/dist/esm/mod.js +9 -0
  112. package/dist/esm/mod.js.map +1 -0
  113. package/dist/esm/src/compat/BSM.js +45 -0
  114. package/dist/esm/src/compat/BSM.js.map +1 -0
  115. package/dist/esm/src/compat/ECIES.js +483 -0
  116. package/dist/esm/src/compat/ECIES.js.map +1 -0
  117. package/dist/esm/src/compat/HD.js +322 -0
  118. package/dist/esm/src/compat/HD.js.map +1 -0
  119. package/dist/esm/src/compat/Mnemonic.js +272 -0
  120. package/dist/esm/src/compat/Mnemonic.js.map +1 -0
  121. package/dist/esm/src/compat/bip-39-wordlist-en.js +2054 -0
  122. package/dist/esm/src/compat/bip-39-wordlist-en.js.map +1 -0
  123. package/dist/esm/src/compat/index.js +5 -0
  124. package/dist/esm/src/compat/index.js.map +1 -0
  125. package/dist/esm/src/messages/EncryptedMessage.js +61 -0
  126. package/dist/esm/src/messages/EncryptedMessage.js.map +1 -0
  127. package/dist/esm/src/messages/SignedMessage.js +77 -0
  128. package/dist/esm/src/messages/SignedMessage.js.map +1 -0
  129. package/dist/esm/src/messages/index.js +3 -0
  130. package/dist/esm/src/messages/index.js.map +1 -0
  131. package/dist/esm/src/primitives/AESGCM.js +371 -0
  132. package/dist/esm/src/primitives/AESGCM.js.map +1 -0
  133. package/dist/esm/src/primitives/BasePoint.js +16 -0
  134. package/dist/esm/src/primitives/BasePoint.js.map +1 -0
  135. package/dist/esm/src/primitives/BigNumber.js +4307 -0
  136. package/dist/esm/src/primitives/BigNumber.js.map +1 -0
  137. package/dist/esm/src/primitives/Curve.js +1141 -0
  138. package/dist/esm/src/primitives/Curve.js.map +1 -0
  139. package/dist/esm/src/primitives/DRBG.js +98 -0
  140. package/dist/esm/src/primitives/DRBG.js.map +1 -0
  141. package/dist/esm/src/primitives/ECDSA.js +161 -0
  142. package/dist/esm/src/primitives/ECDSA.js.map +1 -0
  143. package/dist/esm/src/primitives/Hash.js +1391 -0
  144. package/dist/esm/src/primitives/Hash.js.map +1 -0
  145. package/dist/esm/src/primitives/JacobianPoint.js +398 -0
  146. package/dist/esm/src/primitives/JacobianPoint.js.map +1 -0
  147. package/dist/esm/src/primitives/K256.js +105 -0
  148. package/dist/esm/src/primitives/K256.js.map +1 -0
  149. package/dist/esm/src/primitives/Mersenne.js +117 -0
  150. package/dist/esm/src/primitives/Mersenne.js.map +1 -0
  151. package/dist/esm/src/primitives/MontgomoryMethod.js +149 -0
  152. package/dist/esm/src/primitives/MontgomoryMethod.js.map +1 -0
  153. package/dist/esm/src/primitives/Point.js +816 -0
  154. package/dist/esm/src/primitives/Point.js.map +1 -0
  155. package/dist/esm/src/primitives/PrivateKey.js +240 -0
  156. package/dist/esm/src/primitives/PrivateKey.js.map +1 -0
  157. package/dist/esm/src/primitives/PublicKey.js +162 -0
  158. package/dist/esm/src/primitives/PublicKey.js.map +1 -0
  159. package/dist/esm/src/primitives/Random.js +56 -0
  160. package/dist/esm/src/primitives/Random.js.map +1 -0
  161. package/dist/esm/src/primitives/ReductionContext.js +486 -0
  162. package/dist/esm/src/primitives/ReductionContext.js.map +1 -0
  163. package/dist/esm/src/primitives/Signature.js +360 -0
  164. package/dist/esm/src/primitives/Signature.js.map +1 -0
  165. package/dist/esm/src/primitives/SymmetricKey.js +76 -0
  166. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -0
  167. package/dist/esm/src/primitives/TransactionSignature.js +144 -0
  168. package/dist/esm/src/primitives/TransactionSignature.js.map +1 -0
  169. package/dist/esm/src/primitives/index.js +13 -0
  170. package/dist/esm/src/primitives/index.js.map +1 -0
  171. package/dist/esm/src/primitives/utils.js +609 -0
  172. package/dist/esm/src/primitives/utils.js.map +1 -0
  173. package/dist/esm/src/script/LockingScript.js +29 -0
  174. package/dist/esm/src/script/LockingScript.js.map +1 -0
  175. package/dist/esm/src/script/OP.js +205 -0
  176. package/dist/esm/src/script/OP.js.map +1 -0
  177. package/dist/esm/src/script/Script.js +430 -0
  178. package/dist/esm/src/script/Script.js.map +1 -0
  179. package/dist/esm/src/script/ScriptChunk.js +2 -0
  180. package/dist/esm/src/script/ScriptChunk.js.map +1 -0
  181. package/dist/esm/src/script/ScriptTemplate.js +2 -0
  182. package/dist/esm/src/script/ScriptTemplate.js.map +1 -0
  183. package/dist/esm/src/script/Spend.js +1240 -0
  184. package/dist/esm/src/script/Spend.js.map +1 -0
  185. package/dist/esm/src/script/UnlockingScript.js +29 -0
  186. package/dist/esm/src/script/UnlockingScript.js.map +1 -0
  187. package/dist/esm/src/script/index.js +7 -0
  188. package/dist/esm/src/script/index.js.map +1 -0
  189. package/dist/esm/src/script/templates/P2PKH.js +113 -0
  190. package/dist/esm/src/script/templates/P2PKH.js.map +1 -0
  191. package/dist/esm/src/script/templates/RPuzzle.js +119 -0
  192. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -0
  193. package/dist/esm/src/script/templates/index.js +3 -0
  194. package/dist/esm/src/script/templates/index.js.map +1 -0
  195. package/dist/esm/src/transaction/Broadcaster.js +2 -0
  196. package/dist/esm/src/transaction/Broadcaster.js.map +1 -0
  197. package/dist/esm/src/transaction/ChainTracker.js +2 -0
  198. package/dist/esm/src/transaction/ChainTracker.js.map +1 -0
  199. package/dist/esm/src/transaction/FeeModel.js +2 -0
  200. package/dist/esm/src/transaction/FeeModel.js.map +1 -0
  201. package/dist/esm/src/transaction/MerklePath.js +237 -0
  202. package/dist/esm/src/transaction/MerklePath.js.map +1 -0
  203. package/dist/esm/src/transaction/Transaction.js +617 -0
  204. package/dist/esm/src/transaction/Transaction.js.map +1 -0
  205. package/dist/esm/src/transaction/TransactionInput.js +2 -0
  206. package/dist/esm/src/transaction/TransactionInput.js.map +1 -0
  207. package/dist/esm/src/transaction/TransactionOutput.js +2 -0
  208. package/dist/esm/src/transaction/TransactionOutput.js.map +1 -0
  209. package/dist/esm/src/transaction/broadcasters/ARC.js +111 -0
  210. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -0
  211. package/dist/esm/src/transaction/broadcasters/index.js +2 -0
  212. package/dist/esm/src/transaction/broadcasters/index.js.map +1 -0
  213. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js +71 -0
  214. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -0
  215. package/dist/esm/src/transaction/fee-models/index.js +2 -0
  216. package/dist/esm/src/transaction/fee-models/index.js.map +1 -0
  217. package/dist/esm/src/transaction/index.js +3 -0
  218. package/dist/esm/src/transaction/index.js.map +1 -0
  219. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  220. package/dist/types/mod.d.ts +9 -0
  221. package/dist/types/mod.d.ts.map +1 -0
  222. package/dist/types/src/compat/BSM.d.ts +28 -0
  223. package/dist/types/src/compat/BSM.d.ts.map +1 -0
  224. package/dist/types/src/compat/ECIES.d.ts +62 -0
  225. package/dist/types/src/compat/ECIES.d.ts.map +1 -0
  226. package/dist/types/src/compat/HD.d.ts +131 -0
  227. package/dist/types/src/compat/HD.d.ts.map +1 -0
  228. package/dist/types/src/compat/Mnemonic.d.ts +132 -0
  229. package/dist/types/src/compat/Mnemonic.d.ts.map +1 -0
  230. package/dist/types/src/compat/bip-39-wordlist-en.d.ts +5 -0
  231. package/dist/types/src/compat/bip-39-wordlist-en.d.ts.map +1 -0
  232. package/dist/types/src/compat/index.d.ts +5 -0
  233. package/dist/types/src/compat/index.d.ts.map +1 -0
  234. package/dist/types/src/messages/EncryptedMessage.d.ts +20 -0
  235. package/dist/types/src/messages/EncryptedMessage.d.ts.map +1 -0
  236. package/dist/types/src/messages/SignedMessage.d.ts +21 -0
  237. package/dist/types/src/messages/SignedMessage.d.ts.map +1 -0
  238. package/dist/types/src/messages/index.d.ts +3 -0
  239. package/dist/types/src/messages/index.d.ts.map +1 -0
  240. package/dist/types/src/primitives/AESGCM.d.ts +14 -0
  241. package/dist/types/src/primitives/AESGCM.d.ts.map +1 -0
  242. package/dist/types/src/primitives/BasePoint.d.ts +22 -0
  243. package/dist/types/src/primitives/BasePoint.d.ts.map +1 -0
  244. package/dist/types/src/primitives/BigNumber.d.ts +1895 -0
  245. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -0
  246. package/dist/types/src/primitives/Curve.d.ts +55 -0
  247. package/dist/types/src/primitives/Curve.d.ts.map +1 -0
  248. package/dist/types/src/primitives/DRBG.d.ts +54 -0
  249. package/dist/types/src/primitives/DRBG.d.ts.map +1 -0
  250. package/dist/types/src/primitives/ECDSA.d.ts +39 -0
  251. package/dist/types/src/primitives/ECDSA.d.ts.map +1 -0
  252. package/dist/types/src/primitives/Hash.d.ts +450 -0
  253. package/dist/types/src/primitives/Hash.d.ts.map +1 -0
  254. package/dist/types/src/primitives/JacobianPoint.d.ts +164 -0
  255. package/dist/types/src/primitives/JacobianPoint.d.ts.map +1 -0
  256. package/dist/types/src/primitives/K256.d.ts +53 -0
  257. package/dist/types/src/primitives/K256.d.ts.map +1 -0
  258. package/dist/types/src/primitives/Mersenne.d.ts +72 -0
  259. package/dist/types/src/primitives/Mersenne.d.ts.map +1 -0
  260. package/dist/types/src/primitives/MontgomoryMethod.d.ts +96 -0
  261. package/dist/types/src/primitives/MontgomoryMethod.d.ts.map +1 -0
  262. package/dist/types/src/primitives/Point.d.ts +303 -0
  263. package/dist/types/src/primitives/Point.d.ts.map +1 -0
  264. package/dist/types/src/primitives/PrivateKey.d.ts +174 -0
  265. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -0
  266. package/dist/types/src/primitives/PublicKey.d.ts +120 -0
  267. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -0
  268. package/dist/types/src/primitives/Random.d.ts +14 -0
  269. package/dist/types/src/primitives/Random.d.ts.map +1 -0
  270. package/dist/types/src/primitives/ReductionContext.d.ts +308 -0
  271. package/dist/types/src/primitives/ReductionContext.d.ts.map +1 -0
  272. package/dist/types/src/primitives/Signature.d.ts +162 -0
  273. package/dist/types/src/primitives/Signature.d.ts.map +1 -0
  274. package/dist/types/src/primitives/SymmetricKey.d.ts +55 -0
  275. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -0
  276. package/dist/types/src/primitives/TransactionSignature.d.ts +36 -0
  277. package/dist/types/src/primitives/TransactionSignature.d.ts.map +1 -0
  278. package/dist/types/src/primitives/index.d.ts +13 -0
  279. package/dist/types/src/primitives/index.d.ts.map +1 -0
  280. package/dist/types/src/primitives/utils.d.ts +124 -0
  281. package/dist/types/src/primitives/utils.d.ts.map +1 -0
  282. package/dist/types/src/script/LockingScript.d.ts +25 -0
  283. package/dist/types/src/script/LockingScript.d.ts.map +1 -0
  284. package/dist/types/src/script/OP.d.ts +193 -0
  285. package/dist/types/src/script/OP.d.ts.map +1 -0
  286. package/dist/types/src/script/Script.d.ts +148 -0
  287. package/dist/types/src/script/Script.d.ts.map +1 -0
  288. package/dist/types/src/script/ScriptChunk.d.ts +8 -0
  289. package/dist/types/src/script/ScriptChunk.d.ts.map +1 -0
  290. package/dist/types/src/script/ScriptTemplate.d.ts +33 -0
  291. package/dist/types/src/script/ScriptTemplate.d.ts.map +1 -0
  292. package/dist/types/src/script/Spend.d.ts +103 -0
  293. package/dist/types/src/script/Spend.d.ts.map +1 -0
  294. package/dist/types/src/script/UnlockingScript.d.ts +25 -0
  295. package/dist/types/src/script/UnlockingScript.d.ts.map +1 -0
  296. package/dist/types/src/script/index.d.ts +8 -0
  297. package/dist/types/src/script/index.d.ts.map +1 -0
  298. package/dist/types/src/script/templates/P2PKH.d.ts +40 -0
  299. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -0
  300. package/dist/types/src/script/templates/RPuzzle.d.ts +47 -0
  301. package/dist/types/src/script/templates/RPuzzle.d.ts.map +1 -0
  302. package/dist/types/src/script/templates/index.d.ts +3 -0
  303. package/dist/types/src/script/templates/index.d.ts.map +1 -0
  304. package/dist/types/src/transaction/Broadcaster.d.ts +39 -0
  305. package/dist/types/src/transaction/Broadcaster.d.ts.map +1 -0
  306. package/dist/types/src/transaction/ChainTracker.d.ts +23 -0
  307. package/dist/types/src/transaction/ChainTracker.d.ts.map +1 -0
  308. package/dist/types/src/transaction/FeeModel.d.ts +12 -0
  309. package/dist/types/src/transaction/FeeModel.d.ts.map +1 -0
  310. package/dist/types/src/transaction/MerklePath.d.ts +91 -0
  311. package/dist/types/src/transaction/MerklePath.d.ts.map +1 -0
  312. package/dist/types/src/transaction/Transaction.d.ts +215 -0
  313. package/dist/types/src/transaction/Transaction.d.ts.map +1 -0
  314. package/dist/types/src/transaction/TransactionInput.d.ts +63 -0
  315. package/dist/types/src/transaction/TransactionInput.d.ts.map +1 -0
  316. package/dist/types/src/transaction/TransactionOutput.d.ts +36 -0
  317. package/dist/types/src/transaction/TransactionOutput.d.ts.map +1 -0
  318. package/dist/types/src/transaction/broadcasters/ARC.d.ts +28 -0
  319. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -0
  320. package/dist/types/src/transaction/broadcasters/index.d.ts +2 -0
  321. package/dist/types/src/transaction/broadcasters/index.d.ts.map +1 -0
  322. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts +26 -0
  323. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -0
  324. package/dist/types/src/transaction/fee-models/index.d.ts +2 -0
  325. package/dist/types/src/transaction/fee-models/index.d.ts.map +1 -0
  326. package/dist/types/src/transaction/index.d.ts +7 -0
  327. package/dist/types/src/transaction/index.d.ts.map +1 -0
  328. package/dist/types/tsconfig.types.tsbuildinfo +1 -0
  329. package/package.json +1 -1
@@ -0,0 +1,819 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const BasePoint_js_1 = __importDefault(require("./BasePoint.js"));
7
+ const JacobianPoint_js_1 = __importDefault(require("./JacobianPoint.js"));
8
+ const BigNumber_js_1 = __importDefault(require("./BigNumber.js"));
9
+ const utils_js_1 = require("./utils.js");
10
+ const ReductionContext_js_1 = __importDefault(require("./ReductionContext.js"));
11
+ /**
12
+ * `Point` class is a representation of an elliptic curve point with affine coordinates.
13
+ * It extends the functionality of BasePoint and carries x, y coordinates of point on the curve.
14
+ * It also introduces new methods for handling Point operations in elliptic curve.
15
+ *
16
+ * @class Point
17
+ * @extends {BasePoint}
18
+ *
19
+ * @property x - The x-coordinate of the point.
20
+ * @property y - The y-coordinate of the point.
21
+ * @property inf - Flag to record if the point is at infinity in the Elliptic Curve.
22
+ */
23
+ class Point extends BasePoint_js_1.default {
24
+ /**
25
+ * Creates a point object from a given string. This string can represent coordinates in hex format, or points
26
+ * in multiple established formats.
27
+ * The function verifies the integrity of the provided data and throws errors if inconsistencies are found.
28
+ *
29
+ * @method fromString
30
+ * @static
31
+ * @param str - The point representation string.
32
+ * @returns Returns a new point representing the given string.
33
+ * @throws `Error` If the point string value has a wrong length.
34
+ * @throws `Error` If the point format is unknown.
35
+ *
36
+ * @example
37
+ * const pointStr = 'abcdef';
38
+ * const point = Point.fromString(pointStr);
39
+ */
40
+ static fromString(str) {
41
+ const bytes = (0, utils_js_1.toArray)(str, 'hex');
42
+ const len = 32;
43
+ // uncompressed, hybrid-odd, hybrid-even
44
+ if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
45
+ bytes.length - 1 === 2 * len) {
46
+ if (bytes[0] === 0x06) {
47
+ if (bytes[bytes.length - 1] % 2 !== 0) {
48
+ throw new Error('Point string value is wrong length');
49
+ }
50
+ }
51
+ else if (bytes[0] === 0x07) {
52
+ if (bytes[bytes.length - 1] % 2 !== 1) {
53
+ throw new Error('Point string value is wrong length');
54
+ }
55
+ }
56
+ const res = new Point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len));
57
+ return res;
58
+ }
59
+ else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
60
+ bytes.length - 1 === len) {
61
+ return Point.fromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
62
+ }
63
+ throw new Error('Unknown point format');
64
+ }
65
+ /**
66
+ * Generates a point from an x coordinate and a boolean indicating whether the corresponding
67
+ * y coordinate is odd.
68
+ *
69
+ * @method fromX
70
+ * @static
71
+ * @param x - The x coordinate of the point.
72
+ * @param odd - Boolean indicating whether the corresponding y coordinate is odd or not.
73
+ * @returns Returns the new point.
74
+ * @throws `Error` If the point is invalid.
75
+ *
76
+ * @example
77
+ * const xCoordinate = new BigNumber('10');
78
+ * const point = Point.fromX(xCoordinate, true);
79
+ */
80
+ static fromX(x, odd) {
81
+ const red = new ReductionContext_js_1.default('k256');
82
+ const a = new BigNumber_js_1.default(0).toRed(red);
83
+ const b = new BigNumber_js_1.default(7).toRed(red);
84
+ const zero = new BigNumber_js_1.default(0).toRed(red);
85
+ if (!BigNumber_js_1.default.isBN(x)) {
86
+ x = new BigNumber_js_1.default(x, 16);
87
+ }
88
+ x = x;
89
+ if (x.red == null) {
90
+ x = x.toRed(red);
91
+ }
92
+ const y2 = x.redSqr().redMul(x).redIAdd(x.redMul(a)).redIAdd(b);
93
+ let y = y2.redSqrt();
94
+ if (y.redSqr().redSub(y2).cmp(zero) !== 0) {
95
+ throw new Error('invalid point');
96
+ }
97
+ // XXX Is there any way to tell if the number is odd without converting it
98
+ // to non-red form?
99
+ const isOdd = y.fromRed().isOdd();
100
+ if ((odd && !isOdd) || (!odd && isOdd)) {
101
+ y = y.redNeg();
102
+ }
103
+ return new Point(x, y);
104
+ }
105
+ /**
106
+ * Generates a point from a serialized JSON object. The function accounts for different options in the JSON object,
107
+ * including precomputed values for optimization of EC operations, and calls another helper function to turn nested
108
+ * JSON points into proper Point objects.
109
+ *
110
+ * @method fromJSON
111
+ * @static
112
+ * @param obj - An object or array that holds the data for the point.
113
+ * @param isRed - A boolean to direct how the Point is constructed from the JSON object.
114
+ * @returns Returns a new point based on the deserialized JSON object.
115
+ *
116
+ * @example
117
+ * const serializedPoint = '{"x":52,"y":15}';
118
+ * const point = Point.fromJSON(serializedPoint, true);
119
+ */
120
+ static fromJSON(obj, isRed) {
121
+ if (typeof obj === 'string') {
122
+ obj = JSON.parse(obj);
123
+ }
124
+ const res = new Point(obj[0], obj[1], isRed);
125
+ if (typeof obj[2] !== 'object') {
126
+ return res;
127
+ }
128
+ const obj2point = (obj) => {
129
+ return new Point(obj[0], obj[1], isRed);
130
+ };
131
+ const pre = obj[2];
132
+ res.precomputed = {
133
+ beta: null,
134
+ doubles: typeof pre.doubles === 'object' && pre.doubles !== null
135
+ ? {
136
+ step: pre.doubles.step,
137
+ points: [res].concat(pre.doubles.points.map(obj2point))
138
+ }
139
+ : undefined,
140
+ naf: typeof pre.naf === 'object' && pre.naf !== null
141
+ ? {
142
+ wnd: pre.naf.wnd,
143
+ points: [res].concat(pre.naf.points.map(obj2point))
144
+ }
145
+ : undefined
146
+ };
147
+ return res;
148
+ }
149
+ /**
150
+ * @constructor
151
+ * @param x - The x-coordinate of the point. May be a number, a BigNumber, a string (which will be interpreted as hex), a number array, or null. If null, an "Infinity" point is constructed.
152
+ * @param y - The y-coordinate of the point, similar to x.
153
+ * @param isRed - A boolean indicating if the point is a member of the field of integers modulo the k256 prime. Default is true.
154
+ *
155
+ * @example
156
+ * new Point('abc123', 'def456');
157
+ * new Point(null, null); // Generates Infinity point.
158
+ */
159
+ constructor(x, y, isRed = true) {
160
+ super('affine');
161
+ this.precomputed = null;
162
+ if (x === null && y === null) {
163
+ this.x = null;
164
+ this.y = null;
165
+ this.inf = true;
166
+ }
167
+ else {
168
+ if (!BigNumber_js_1.default.isBN(x)) {
169
+ x = new BigNumber_js_1.default(x, 16);
170
+ }
171
+ this.x = x;
172
+ if (!BigNumber_js_1.default.isBN(y)) {
173
+ y = new BigNumber_js_1.default(y, 16);
174
+ }
175
+ this.y = y;
176
+ // Force redgomery representation when loading from JSON
177
+ if (isRed) {
178
+ this.x.forceRed(this.curve.red);
179
+ this.y.forceRed(this.curve.red);
180
+ }
181
+ if (this.x.red === null) {
182
+ this.x = this.x.toRed(this.curve.red);
183
+ }
184
+ if (this.y.red === null) {
185
+ this.y = this.y.toRed(this.curve.red);
186
+ }
187
+ this.inf = false;
188
+ }
189
+ }
190
+ /**
191
+ * Validates if a point belongs to the curve. Follows the short Weierstrass
192
+ * equation for elliptic curves: y^2 = x^3 + ax + b.
193
+ *
194
+ * @method validate
195
+ * @returns {boolean} true if the point is on the curve, false otherwise.
196
+ *
197
+ * @example
198
+ * const aPoint = new Point(x, y);
199
+ * const isValid = aPoint.validate();
200
+ */
201
+ validate() {
202
+ return this.curve.validate(this);
203
+ }
204
+ /**
205
+ * Encodes the coordinates of a point into an array or a hexadecimal string.
206
+ * The details of encoding are determined by the optional compact and enc parameters.
207
+ *
208
+ * @method encode
209
+ * @param compact - If true, an additional prefix byte 0x02 or 0x03 based on the 'y' coordinate being even or odd respectively is used. If false, byte 0x04 is used.
210
+ * @param enc - Expects the string 'hex' if hexadecimal string encoding is required instead of an array of numbers.
211
+ * @throws Will throw an error if the specified encoding method is not recognized. Expects 'hex'.
212
+ * @returns If enc is undefined, a byte array representation of the point will be returned. if enc is 'hex', a hexadecimal string representation of the point will be returned.
213
+ *
214
+ * @example
215
+ * const aPoint = new Point(x, y);
216
+ * const encodedPointArray = aPoint.encode();
217
+ * const encodedPointHex = aPoint.encode(true, 'hex');
218
+ */
219
+ encode(compact = true, enc) {
220
+ const len = this.curve.p.byteLength();
221
+ const x = this.getX().toArray('be', len);
222
+ let res;
223
+ if (compact) {
224
+ res = [this.getY().isEven() ? 0x02 : 0x03].concat(x);
225
+ }
226
+ else {
227
+ res = [0x04].concat(x, this.getY().toArray('be', len));
228
+ }
229
+ if (enc !== 'hex') {
230
+ return res;
231
+ }
232
+ else {
233
+ return (0, utils_js_1.toHex)(res);
234
+ }
235
+ }
236
+ /**
237
+ * Converts the point coordinates to a hexadecimal string. A wrapper method
238
+ * for encode. Byte 0x02 or 0x03 is used as prefix based on the 'y' coordinate being even or odd respectively.
239
+ *
240
+ * @method toString
241
+ * @returns {string} A hexadecimal string representation of the point coordinates.
242
+ *
243
+ * @example
244
+ * const aPoint = new Point(x, y);
245
+ * const stringPoint = aPoint.toString();
246
+ */
247
+ toString() {
248
+ return this.encode(true, 'hex');
249
+ }
250
+ /**
251
+ * Exports the x and y coordinates of the point, and the precomputed doubles and non-adjacent form (NAF) for optimization. The output is an array.
252
+ *
253
+ * @method toJSON
254
+ * @returns An Array where first two elements are the coordinates of the point and optional third element is an object with doubles and NAF points.
255
+ *
256
+ * @example
257
+ * const aPoint = new Point(x, y);
258
+ * const jsonPoint = aPoint.toJSON();
259
+ */
260
+ toJSON() {
261
+ if (this.precomputed == null) {
262
+ return [this.x, this.y];
263
+ }
264
+ return [this.x, this.y, typeof this.precomputed === 'object' && this.precomputed !== null
265
+ ? {
266
+ doubles: (this.precomputed.doubles != null)
267
+ ? {
268
+ step: this.precomputed.doubles.step,
269
+ points: this.precomputed.doubles.points.slice(1)
270
+ }
271
+ : undefined,
272
+ naf: (this.precomputed.naf != null)
273
+ ? {
274
+ wnd: this.precomputed.naf.wnd,
275
+ points: this.precomputed.naf.points.slice(1)
276
+ }
277
+ : undefined
278
+ }
279
+ : undefined];
280
+ }
281
+ /**
282
+ * Provides the point coordinates in a human-readable string format for debugging purposes.
283
+ *
284
+ * @method inspect
285
+ * @returns String of the format '<EC Point x: x-coordinate y: y-coordinate>', or '<EC Point Infinity>' if the point is at infinity.
286
+ *
287
+ * @example
288
+ * const aPoint = new Point(x, y);
289
+ * console.log(aPoint.inspect());
290
+ */
291
+ inspect() {
292
+ if (this.isInfinity()) {
293
+ return '<EC Point Infinity>';
294
+ }
295
+ return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
296
+ ' y: ' + this.y.fromRed().toString(16, 2) + '>';
297
+ }
298
+ /**
299
+ * Checks if the point is at infinity.
300
+ * @method isInfinity
301
+ * @returns Returns whether or not the point is at infinity.
302
+ *
303
+ * @example
304
+ * const p = new Point(null, null);
305
+ * console.log(p.isInfinity()); // outputs: true
306
+ */
307
+ isInfinity() {
308
+ return this.inf;
309
+ }
310
+ /**
311
+ * Adds another Point to this Point, returning a new Point.
312
+ *
313
+ * @method add
314
+ * @param p - The Point to add to this one.
315
+ * @returns A new Point that results from the addition.
316
+ *
317
+ * @example
318
+ * const p1 = new Point(1, 2);
319
+ * const p2 = new Point(2, 3);
320
+ * const result = p1.add(p2);
321
+ */
322
+ add(p) {
323
+ // O + P = P
324
+ if (this.inf) {
325
+ return p;
326
+ }
327
+ // P + O = P
328
+ if (p.inf) {
329
+ return this;
330
+ }
331
+ // P + P = 2P
332
+ if (this.eq(p)) {
333
+ return this.dbl();
334
+ }
335
+ // P + (-P) = O
336
+ if (this.neg().eq(p)) {
337
+ return new Point(null, null);
338
+ }
339
+ // P + Q = O
340
+ if (this.x.cmp(p.x) === 0) {
341
+ return new Point(null, null);
342
+ }
343
+ let c = this.y.redSub(p.y);
344
+ if (c.cmpn(0) !== 0) {
345
+ c = c.redMul(this.x.redSub(p.x).redInvm());
346
+ }
347
+ const nx = c.redSqr().redISub(this.x).redISub(p.x);
348
+ const ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
349
+ return new Point(nx, ny);
350
+ }
351
+ /**
352
+ * Doubles the current point.
353
+ *
354
+ * @method dbl
355
+ *
356
+ * @example
357
+ * const P = new Point('123', '456');
358
+ * const result = P.dbl();
359
+ * */
360
+ dbl() {
361
+ if (this.inf) {
362
+ return this;
363
+ }
364
+ // 2P = O
365
+ const ys1 = this.y.redAdd(this.y);
366
+ if (ys1.cmpn(0) === 0) {
367
+ return new Point(null, null);
368
+ }
369
+ const a = this.curve.a;
370
+ const x2 = this.x.redSqr();
371
+ const dyinv = ys1.redInvm();
372
+ const c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
373
+ const nx = c.redSqr().redISub(this.x.redAdd(this.x));
374
+ const ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
375
+ return new Point(nx, ny);
376
+ }
377
+ /**
378
+ * Returns X coordinate of point
379
+ *
380
+ * @example
381
+ * const P = new Point('123', '456');
382
+ * const x = P.getX();
383
+ */
384
+ getX() {
385
+ return this.x.fromRed();
386
+ }
387
+ /**
388
+ * Returns X coordinate of point
389
+ *
390
+ * @example
391
+ * const P = new Point('123', '456');
392
+ * const x = P.getX();
393
+ */
394
+ getY() {
395
+ return this.y.fromRed();
396
+ }
397
+ /**
398
+ * Multiplies this Point by a scalar value, returning a new Point.
399
+ *
400
+ * @method mul
401
+ * @param k - The scalar value to multiply this Point by.
402
+ * @returns A new Point that results from the multiplication.
403
+ *
404
+ * @example
405
+ * const p = new Point(1, 2);
406
+ * const result = p.mul(2); // this doubles the Point
407
+ */
408
+ mul(k) {
409
+ if (!BigNumber_js_1.default.isBN(k)) {
410
+ k = new BigNumber_js_1.default(k, 16);
411
+ }
412
+ k = k;
413
+ if (this.isInfinity()) {
414
+ return this;
415
+ }
416
+ else if (this._hasDoubles(k)) {
417
+ return this._fixedNafMul(k);
418
+ }
419
+ else {
420
+ return this._endoWnafMulAdd([this], [k]);
421
+ }
422
+ }
423
+ /**
424
+ * Performs a multiplication and addition operation in a single step.
425
+ * Multiplies this Point by k1, adds the resulting Point to the result of p2 multiplied by k2.
426
+ *
427
+ * @method mulAdd
428
+ * @param k1 - The scalar value to multiply this Point by.
429
+ * @param p2 - The other Point to be involved in the operation.
430
+ * @param k2 - The scalar value to multiply the Point p2 by.
431
+ * @returns A Point that results from the combined multiplication and addition operations.
432
+ *
433
+ * @example
434
+ * const p1 = new Point(1, 2);
435
+ * const p2 = new Point(2, 3);
436
+ * const result = p1.mulAdd(2, p2, 3);
437
+ */
438
+ mulAdd(k1, p2, k2) {
439
+ const points = [this, p2];
440
+ const coeffs = [k1, k2];
441
+ return this._endoWnafMulAdd(points, coeffs);
442
+ }
443
+ /**
444
+ * Performs the Jacobian multiplication and addition operation in a single
445
+ * step. Instead of returning a regular Point, the result is a JacobianPoint.
446
+ *
447
+ * @method jmulAdd
448
+ * @param k1 - The scalar value to multiply this Point by.
449
+ * @param p2 - The other Point to be involved in the operation
450
+ * @param k2 - The scalar value to multiply the Point p2 by.
451
+ * @returns A JacobianPoint that results from the combined multiplication and addition operation.
452
+ *
453
+ * @example
454
+ * const p1 = new Point(1, 2);
455
+ * const p2 = new Point(2, 3);
456
+ * const result = p1.jmulAdd(2, p2, 3);
457
+ */
458
+ jmulAdd(k1, p2, k2) {
459
+ const points = [this, p2];
460
+ const coeffs = [k1, k2];
461
+ return this._endoWnafMulAdd(points, coeffs, true);
462
+ }
463
+ /**
464
+ * Checks if the Point instance is equal to another given Point.
465
+ *
466
+ * @method eq
467
+ * @param p - The Point to be checked if equal to the current instance.
468
+ *
469
+ * @returns Whether the two Point instances are equal. Both the 'x' and 'y' coordinates have to match, and both points have to either be valid or at infinity for equality. If both conditions are true, it returns true, else it returns false.
470
+ *
471
+ * @example
472
+ * const p1 = new Point(5, 20);
473
+ * const p2 = new Point(5, 20);
474
+ * const areEqual = p1.eq(p2); // returns true
475
+ */
476
+ eq(p) {
477
+ return this === p || ((this.inf === p.inf) &&
478
+ (this.inf || (this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0)));
479
+ }
480
+ /**
481
+ * Negate a point. The negation of a point P is the mirror of P about x-axis.
482
+ *
483
+ * @method neg
484
+ *
485
+ * @example
486
+ * const P = new Point('123', '456');
487
+ * const result = P.neg();
488
+ */
489
+ neg(_precompute) {
490
+ if (this.inf) {
491
+ return this;
492
+ }
493
+ const res = new Point(this.x, this.y.redNeg());
494
+ if (_precompute && (this.precomputed != null)) {
495
+ const pre = this.precomputed;
496
+ const negate = (p) => p.neg();
497
+ res.precomputed = {
498
+ naf: (pre.naf != null) && {
499
+ wnd: pre.naf.wnd,
500
+ points: pre.naf.points.map(negate)
501
+ },
502
+ doubles: (pre.doubles != null) && {
503
+ step: pre.doubles.step,
504
+ points: pre.doubles.points.map((p) => p.neg())
505
+ },
506
+ beta: undefined
507
+ };
508
+ }
509
+ return res;
510
+ }
511
+ /**
512
+ * Performs the "doubling" operation on the Point a given number of times.
513
+ * This is used in elliptic curve operations to perform multiplication by 2, multiple times.
514
+ * If the point is at infinity, it simply returns the point because doubling
515
+ * a point at infinity is still infinity.
516
+ *
517
+ * @method dblp
518
+ * @param k - The number of times the "doubling" operation is to be performed on the Point.
519
+ * @returns The Point after 'k' "doubling" operations have been performed.
520
+ *
521
+ * @example
522
+ * const p = new Point(5, 20);
523
+ * const doubledPoint = p.dblp(10); // returns the point after "doubled" 10 times
524
+ */
525
+ dblp(k) {
526
+ /* eslint-disable @typescript-eslint/no-this-alias */
527
+ let r = this;
528
+ for (let i = 0; i < k; i++) {
529
+ r = r.dbl();
530
+ }
531
+ return r;
532
+ }
533
+ /**
534
+ * Converts the point to a Jacobian point. If the point is at infinity, the corresponding Jacobian point
535
+ * will also be at infinity.
536
+ *
537
+ * @method toJ
538
+ * @returns Returns a new Jacobian point based on the current point.
539
+ *
540
+ * @example
541
+ * const point = new Point(xCoordinate, yCoordinate);
542
+ * const jacobianPoint = point.toJ();
543
+ */
544
+ toJ() {
545
+ if (this.inf) {
546
+ return new JacobianPoint_js_1.default(null, null, null);
547
+ }
548
+ const res = new JacobianPoint_js_1.default(this.x, this.y, this.curve.one);
549
+ return res;
550
+ }
551
+ _getBeta() {
552
+ if (typeof this.curve.endo !== 'object') {
553
+ return;
554
+ }
555
+ const pre = this.precomputed;
556
+ if (typeof pre === 'object' && pre !== null && typeof pre.beta === 'object' && pre.beta !== null) {
557
+ return pre.beta;
558
+ }
559
+ const beta = new Point(this.x.redMul(this.curve.endo.beta), this.y);
560
+ if (pre != null) {
561
+ const curve = this.curve;
562
+ const endoMul = (p) => {
563
+ return new Point(p.x.redMul(curve.endo.beta), p.y);
564
+ };
565
+ pre.beta = beta;
566
+ beta.precomputed = {
567
+ beta: null,
568
+ naf: (pre.naf != null)
569
+ ? {
570
+ wnd: pre.naf.wnd,
571
+ points: pre.naf.points.map(endoMul)
572
+ }
573
+ : undefined,
574
+ doubles: (pre.doubles != null)
575
+ ? {
576
+ step: pre.doubles.step,
577
+ points: pre.doubles.points.map(endoMul)
578
+ }
579
+ : undefined
580
+ };
581
+ }
582
+ return beta;
583
+ }
584
+ _fixedNafMul(k) {
585
+ if (typeof this.precomputed !== 'object' || this.precomputed === null) {
586
+ throw new Error('_fixedNafMul requires precomputed values for the point');
587
+ }
588
+ const doubles = this._getDoubles();
589
+ const naf = this.curve.getNAF(k, 1, this.curve._bitLength);
590
+ let I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
591
+ I /= 3;
592
+ // Translate into more windowed form
593
+ const repr = [];
594
+ for (let j = 0; j < naf.length; j += doubles.step) {
595
+ let nafW = 0;
596
+ for (let k = j + doubles.step - 1; k >= j; k--) {
597
+ nafW = (nafW << 1) + naf[k];
598
+ }
599
+ repr.push(nafW);
600
+ }
601
+ let a = new JacobianPoint_js_1.default(null, null, null);
602
+ let b = new JacobianPoint_js_1.default(null, null, null);
603
+ for (let i = I; i > 0; i--) {
604
+ for (let j = 0; j < repr.length; j++) {
605
+ const nafW = repr[j];
606
+ if (nafW === i) {
607
+ b = b.mixedAdd(doubles.points[j]);
608
+ }
609
+ else if (nafW === -i) {
610
+ b = b.mixedAdd((doubles.points[j]).neg());
611
+ }
612
+ }
613
+ a = a.add(b);
614
+ }
615
+ return a.toP();
616
+ }
617
+ _wnafMulAdd(defW, points, coeffs, len, jacobianResult) {
618
+ const wndWidth = this.curve._wnafT1;
619
+ const wnd = this.curve._wnafT2;
620
+ const naf = this.curve._wnafT3;
621
+ // Fill all arrays
622
+ let max = 0;
623
+ for (let i = 0; i < len; i++) {
624
+ const p = points[i];
625
+ const nafPoints = p._getNAFPoints(defW);
626
+ wndWidth[i] = nafPoints.wnd;
627
+ wnd[i] = nafPoints.points;
628
+ }
629
+ // Comb small window NAFs
630
+ for (let i = len - 1; i >= 1; i -= 2) {
631
+ const a = i - 1;
632
+ const b = i;
633
+ if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
634
+ naf[a] = this.curve
635
+ .getNAF(coeffs[a], wndWidth[a], this.curve._bitLength);
636
+ naf[b] = this.curve
637
+ .getNAF(coeffs[b], wndWidth[b], this.curve._bitLength);
638
+ max = Math.max(naf[a].length, max);
639
+ max = Math.max(naf[b].length, max);
640
+ continue;
641
+ }
642
+ const comb = [
643
+ points[a],
644
+ null,
645
+ null,
646
+ points[b] /* 7 */
647
+ ];
648
+ // Try to avoid Projective points, if possible
649
+ if (points[a].y.cmp(points[b].y) === 0) {
650
+ comb[1] = points[a].add(points[b]);
651
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
652
+ }
653
+ else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
654
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
655
+ comb[2] = points[a].add(points[b].neg());
656
+ }
657
+ else {
658
+ comb[1] = points[a].toJ().mixedAdd(points[b]);
659
+ comb[2] = points[a].toJ().mixedAdd(points[b].neg());
660
+ }
661
+ const index = [
662
+ -3,
663
+ -1,
664
+ -5,
665
+ -7,
666
+ 0,
667
+ 7,
668
+ 5,
669
+ 1,
670
+ 3 /* 1 1 */
671
+ ];
672
+ const jsf = this.curve.getJSF(coeffs[a], coeffs[b]);
673
+ max = Math.max(jsf[0].length, max);
674
+ naf[a] = new Array(max);
675
+ naf[b] = new Array(max);
676
+ for (let j = 0; j < max; j++) {
677
+ const ja = jsf[0][j] | 0;
678
+ const jb = jsf[1][j] | 0;
679
+ naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
680
+ naf[b][j] = 0;
681
+ wnd[a] = comb;
682
+ }
683
+ }
684
+ let acc = new JacobianPoint_js_1.default(null, null, null);
685
+ const tmp = this.curve._wnafT4;
686
+ for (let i = max; i >= 0; i--) {
687
+ let k = 0;
688
+ while (i >= 0) {
689
+ let zero = true;
690
+ for (let j = 0; j < len; j++) {
691
+ tmp[j] = naf[j][i] | 0;
692
+ if (tmp[j] !== 0) {
693
+ zero = false;
694
+ }
695
+ }
696
+ if (!zero) {
697
+ break;
698
+ }
699
+ k++;
700
+ i--;
701
+ }
702
+ if (i >= 0) {
703
+ k++;
704
+ }
705
+ acc = acc.dblp(k);
706
+ if (i < 0) {
707
+ break;
708
+ }
709
+ for (let j = 0; j < len; j++) {
710
+ const z = tmp[j];
711
+ let p;
712
+ if (z === 0) {
713
+ continue;
714
+ }
715
+ else if (z > 0) {
716
+ p = wnd[j][(z - 1) >> 1];
717
+ }
718
+ else if (z < 0) {
719
+ p = wnd[j][(-z - 1) >> 1].neg();
720
+ }
721
+ if (p.type === 'affine') {
722
+ acc = acc.mixedAdd(p);
723
+ }
724
+ else {
725
+ acc = acc.add(p);
726
+ }
727
+ }
728
+ }
729
+ // Zeroify references
730
+ for (let i = 0; i < len; i++) {
731
+ wnd[i] = null;
732
+ }
733
+ if (jacobianResult) {
734
+ return acc;
735
+ }
736
+ else {
737
+ return acc.toP();
738
+ }
739
+ }
740
+ _endoWnafMulAdd(points, coeffs, jacobianResult) {
741
+ const npoints = this.curve._endoWnafT1;
742
+ const ncoeffs = this.curve._endoWnafT2;
743
+ let i;
744
+ for (i = 0; i < points.length; i++) {
745
+ const split = this.curve._endoSplit(coeffs[i]);
746
+ let p = points[i];
747
+ let beta = p._getBeta();
748
+ if (split.k1.negative !== 0) {
749
+ split.k1.ineg();
750
+ p = p.neg(true);
751
+ }
752
+ if (split.k2.negative !== 0) {
753
+ split.k2.ineg();
754
+ beta = beta.neg(true);
755
+ }
756
+ npoints[i * 2] = p;
757
+ npoints[i * 2 + 1] = beta;
758
+ ncoeffs[i * 2] = split.k1;
759
+ ncoeffs[i * 2 + 1] = split.k2;
760
+ }
761
+ const res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
762
+ // Clean-up references to points and coefficients
763
+ for (let j = 0; j < i * 2; j++) {
764
+ npoints[j] = null;
765
+ ncoeffs[j] = null;
766
+ }
767
+ return res;
768
+ }
769
+ _hasDoubles(k) {
770
+ if (this.precomputed == null) {
771
+ return false;
772
+ }
773
+ const doubles = this.precomputed.doubles;
774
+ if (typeof doubles !== 'object') {
775
+ return false;
776
+ }
777
+ return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
778
+ }
779
+ ;
780
+ _getDoubles(step, power) {
781
+ if (typeof this.precomputed === 'object' && this.precomputed !== null &&
782
+ typeof this.precomputed.doubles === 'object' &&
783
+ this.precomputed.doubles !== null) {
784
+ return this.precomputed.doubles;
785
+ }
786
+ const doubles = [this];
787
+ /* eslint-disable @typescript-eslint/no-this-alias */
788
+ let acc = this;
789
+ for (let i = 0; i < power; i += step) {
790
+ for (let j = 0; j < step; j++) {
791
+ acc = acc.dbl();
792
+ }
793
+ doubles.push(acc);
794
+ }
795
+ return {
796
+ step,
797
+ points: doubles
798
+ };
799
+ }
800
+ ;
801
+ _getNAFPoints(wnd) {
802
+ if (typeof this.precomputed === 'object' && this.precomputed !== null &&
803
+ typeof this.precomputed.naf === 'object' && this.precomputed.naf !== null) {
804
+ return this.precomputed.naf;
805
+ }
806
+ const res = [this];
807
+ const max = (1 << wnd) - 1;
808
+ const dbl = max === 1 ? null : this.dbl();
809
+ for (let i = 1; i < max; i++) {
810
+ res[i] = res[i - 1].add(dbl);
811
+ }
812
+ return {
813
+ wnd,
814
+ points: res
815
+ };
816
+ }
817
+ }
818
+ exports.default = Point;
819
+ //# sourceMappingURL=Point.js.map