@bsv/sdk 1.0.29 → 1.0.31

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