@hfunlabs/hyperliquid 0.30.0-hfunlabs.1 → 0.30.2-hfunlabs.2

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 (397) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +58 -0
  4. package/esm/_dnt.shims.js.map +1 -0
  5. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts +195 -0
  6. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts.map +1 -0
  7. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js +457 -0
  8. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js.map +1 -0
  9. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts +90 -0
  10. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts.map +1 -0
  11. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js +207 -0
  12. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js.map +1 -0
  13. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts +159 -0
  14. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js +555 -0
  16. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js.map +1 -0
  17. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts +325 -0
  18. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js +1222 -0
  20. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js.map +1 -0
  21. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts +76 -0
  22. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts.map +1 -0
  23. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js +283 -0
  24. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js.map +1 -0
  25. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts +103 -0
  26. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.js +241 -0
  28. package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.js.map +1 -0
  29. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts +49 -0
  30. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js +147 -0
  32. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js.map +1 -0
  33. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts +55 -0
  34. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts.map +1 -0
  35. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js +67 -0
  36. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js.map +1 -0
  37. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts +36 -0
  38. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js +90 -0
  40. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js.map +1 -0
  41. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts +199 -0
  42. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js +397 -0
  44. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js.map +1 -0
  45. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts +58 -0
  46. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts.map +1 -0
  47. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js +254 -0
  48. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js.map +1 -0
  49. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts +124 -0
  50. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js +243 -0
  52. package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js.map +1 -0
  53. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts +44 -0
  54. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts.map +1 -0
  55. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js +144 -0
  56. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js.map +1 -0
  57. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts +38 -0
  58. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts.map +1 -0
  59. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js +96 -0
  60. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js.map +1 -0
  61. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts +23 -0
  62. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js +98 -0
  64. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js.map +1 -0
  65. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts +300 -0
  66. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js +535 -0
  68. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js.map +1 -0
  69. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts +98 -0
  70. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts.map +1 -0
  71. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js +207 -0
  72. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js.map +1 -0
  73. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts +78 -0
  74. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js +298 -0
  76. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js.map +1 -0
  77. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts +6 -0
  78. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts.map +1 -0
  79. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js +6 -0
  80. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js.map +1 -0
  81. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts +66 -0
  82. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts.map +1 -0
  83. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js +180 -0
  84. package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js.map +1 -0
  85. package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts +877 -0
  86. package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts.map +1 -0
  87. package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js +2001 -0
  88. package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js.map +1 -0
  89. package/esm/deps/jsr.io/@scure/base/2.0.0/index.d.ts +294 -0
  90. package/esm/deps/jsr.io/@scure/base/2.0.0/index.d.ts.map +1 -0
  91. package/esm/deps/jsr.io/@scure/base/2.0.0/index.js +704 -0
  92. package/esm/deps/jsr.io/@scure/base/2.0.0/index.js.map +1 -0
  93. package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts +93 -0
  94. package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts.map +1 -0
  95. package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js +137 -0
  96. package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js.map +1 -0
  97. package/esm/src/api/exchange/_methods/_base/_nonce.d.ts +3 -2
  98. package/esm/src/api/exchange/_methods/_base/_nonce.d.ts.map +1 -1
  99. package/esm/src/api/exchange/_methods/_base/_nonce.js +3 -2
  100. package/esm/src/api/exchange/_methods/_base/_nonce.js.map +1 -1
  101. package/esm/src/api/exchange/_methods/_base/_semaphore.d.ts +7 -6
  102. package/esm/src/api/exchange/_methods/_base/_semaphore.d.ts.map +1 -1
  103. package/esm/src/api/exchange/_methods/_base/_semaphore.js +34 -47
  104. package/esm/src/api/exchange/_methods/_base/_semaphore.js.map +1 -1
  105. package/esm/src/api/exchange/_methods/_base/execute.d.ts +14 -3
  106. package/esm/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
  107. package/esm/src/api/exchange/_methods/_base/execute.js +44 -10
  108. package/esm/src/api/exchange/_methods/_base/execute.js.map +1 -1
  109. package/esm/src/api/exchange/_methods/batchModify.d.ts +6 -6
  110. package/esm/src/api/exchange/_methods/createVault.d.ts +5 -5
  111. package/esm/src/api/exchange/_methods/modify.d.ts +5 -5
  112. package/esm/src/api/exchange/_methods/order.d.ts +13 -13
  113. package/esm/src/api/exchange/_methods/order.d.ts.map +1 -1
  114. package/esm/src/api/exchange/_methods/order.js +4 -2
  115. package/esm/src/api/exchange/_methods/order.js.map +1 -1
  116. package/esm/src/api/exchange/client.d.ts +1 -1
  117. package/esm/src/api/exchange/client.d.ts.map +1 -1
  118. package/esm/src/api/exchange/client.js.map +1 -1
  119. package/esm/src/api/exchange/mod.d.ts +1 -1
  120. package/esm/src/api/exchange/mod.d.ts.map +1 -1
  121. package/esm/src/api/exchange/mod.js.map +1 -1
  122. package/esm/src/api/info/_methods/_base/commonSchemas.d.ts +8 -8
  123. package/esm/src/api/info/_methods/frontendOpenOrders.d.ts +3 -3
  124. package/esm/src/api/info/_methods/historicalOrders.d.ts +4 -4
  125. package/esm/src/api/info/_methods/l3Orders.d.ts +11 -11
  126. package/esm/src/api/info/_methods/l4Orders.d.ts +6 -6
  127. package/esm/src/api/info/_methods/openOrders.d.ts +3 -3
  128. package/esm/src/api/info/_methods/orderStatus.d.ts +5 -5
  129. package/esm/src/api/info/_methods/recentTrades.d.ts +2 -2
  130. package/esm/src/api/info/_methods/twapHistory.d.ts +4 -4
  131. package/esm/src/api/info/_methods/userFills.d.ts +3 -3
  132. package/esm/src/api/info/_methods/userFillsByTime.d.ts +4 -4
  133. package/esm/src/api/info/_methods/userFunding.d.ts +3 -3
  134. package/esm/src/api/info/_methods/userFunding.js +2 -2
  135. package/esm/src/api/info/_methods/userFunding.js.map +1 -1
  136. package/esm/src/api/info/_methods/userTwapSliceFills.d.ts +4 -4
  137. package/esm/src/api/info/_methods/userTwapSliceFillsByTime.d.ts +5 -5
  138. package/esm/src/api/info/_methods/webData2.d.ts +9 -9
  139. package/esm/src/api/subscription/_methods/assetCtxs.d.ts +2 -0
  140. package/esm/src/api/subscription/_methods/assetCtxs.d.ts.map +1 -1
  141. package/esm/src/api/subscription/_methods/assetCtxs.js.map +1 -1
  142. package/esm/src/api/subscription/_methods/clearinghouseState.d.ts +2 -0
  143. package/esm/src/api/subscription/_methods/clearinghouseState.d.ts.map +1 -1
  144. package/esm/src/api/subscription/_methods/clearinghouseState.js +2 -0
  145. package/esm/src/api/subscription/_methods/clearinghouseState.js.map +1 -1
  146. package/esm/src/api/subscription/_methods/explorerBlock.d.ts +2 -0
  147. package/esm/src/api/subscription/_methods/explorerBlock.d.ts.map +1 -1
  148. package/esm/src/api/subscription/_methods/explorerBlock.js +2 -0
  149. package/esm/src/api/subscription/_methods/explorerBlock.js.map +1 -1
  150. package/esm/src/api/subscription/_methods/explorerTxs.d.ts +2 -0
  151. package/esm/src/api/subscription/_methods/explorerTxs.d.ts.map +1 -1
  152. package/esm/src/api/subscription/_methods/explorerTxs.js +2 -0
  153. package/esm/src/api/subscription/_methods/explorerTxs.js.map +1 -1
  154. package/esm/src/api/subscription/_methods/openOrders.d.ts +5 -5
  155. package/esm/src/api/subscription/_methods/orderUpdates.d.ts +4 -4
  156. package/esm/src/api/subscription/_methods/trades.d.ts +3 -3
  157. package/esm/src/api/subscription/_methods/twapStates.d.ts +9 -4
  158. package/esm/src/api/subscription/_methods/twapStates.d.ts.map +1 -1
  159. package/esm/src/api/subscription/_methods/twapStates.js +6 -1
  160. package/esm/src/api/subscription/_methods/twapStates.js.map +1 -1
  161. package/esm/src/api/subscription/_methods/userEvents.d.ts +17 -17
  162. package/esm/src/api/subscription/_methods/userFills.d.ts +5 -5
  163. package/esm/src/api/subscription/_methods/userHistoricalOrders.d.ts +6 -6
  164. package/esm/src/api/subscription/_methods/userTwapHistory.d.ts +6 -6
  165. package/esm/src/api/subscription/_methods/userTwapSliceFills.d.ts +6 -6
  166. package/esm/src/api/subscription/_methods/webData2.d.ts +11 -11
  167. package/esm/src/signing/_privateKeySigner.js +1 -1
  168. package/esm/src/signing/_privateKeySigner.js.map +1 -1
  169. package/esm/src/signing/mod.js +1 -1
  170. package/esm/src/signing/mod.js.map +1 -1
  171. package/package.json +2 -3
  172. package/script/_dnt.shims.d.ts +2 -0
  173. package/script/_dnt.shims.d.ts.map +1 -0
  174. package/script/_dnt.shims.js +61 -0
  175. package/script/_dnt.shims.js.map +1 -0
  176. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts +195 -0
  177. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts.map +1 -0
  178. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js +468 -0
  179. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js.map +1 -0
  180. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts +90 -0
  181. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts.map +1 -0
  182. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js +215 -0
  183. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js.map +1 -0
  184. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts +159 -0
  185. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts.map +1 -0
  186. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js +578 -0
  187. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js.map +1 -0
  188. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts +325 -0
  189. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts.map +1 -0
  190. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js +1232 -0
  191. package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js.map +1 -0
  192. package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts +76 -0
  193. package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts.map +1 -0
  194. package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js +286 -0
  195. package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js.map +1 -0
  196. package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts +103 -0
  197. package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts.map +1 -0
  198. package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.js +273 -0
  199. package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.js.map +1 -0
  200. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts +49 -0
  201. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts.map +1 -0
  202. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js +153 -0
  203. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js.map +1 -0
  204. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts +55 -0
  205. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts.map +1 -0
  206. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js +90 -0
  207. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js.map +1 -0
  208. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts +36 -0
  209. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts.map +1 -0
  210. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js +95 -0
  211. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js.map +1 -0
  212. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts +199 -0
  213. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts.map +1 -0
  214. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js +439 -0
  215. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js.map +1 -0
  216. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts +58 -0
  217. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts.map +1 -0
  218. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js +259 -0
  219. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js.map +1 -0
  220. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts +124 -0
  221. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts.map +1 -0
  222. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js +304 -0
  223. package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js.map +1 -0
  224. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts +44 -0
  225. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts.map +1 -0
  226. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js +182 -0
  227. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js.map +1 -0
  228. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts +38 -0
  229. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts.map +1 -0
  230. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js +99 -0
  231. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js.map +1 -0
  232. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts +23 -0
  233. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts.map +1 -0
  234. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js +134 -0
  235. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js.map +1 -0
  236. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts +300 -0
  237. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts.map +1 -0
  238. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js +576 -0
  239. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js.map +1 -0
  240. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts +98 -0
  241. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts.map +1 -0
  242. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js +211 -0
  243. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js.map +1 -0
  244. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts +78 -0
  245. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts.map +1 -0
  246. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js +308 -0
  247. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js.map +1 -0
  248. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts +6 -0
  249. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts.map +1 -0
  250. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js +21 -0
  251. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js.map +1 -0
  252. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts +66 -0
  253. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts.map +1 -0
  254. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js +195 -0
  255. package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js.map +1 -0
  256. package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts +877 -0
  257. package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts.map +1 -0
  258. package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js +2032 -0
  259. package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js.map +1 -0
  260. package/script/deps/jsr.io/@scure/base/2.0.0/index.d.ts +294 -0
  261. package/script/deps/jsr.io/@scure/base/2.0.0/index.d.ts.map +1 -0
  262. package/script/deps/jsr.io/@scure/base/2.0.0/index.js +710 -0
  263. package/script/deps/jsr.io/@scure/base/2.0.0/index.js.map +1 -0
  264. package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts +93 -0
  265. package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts.map +1 -0
  266. package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js +141 -0
  267. package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js.map +1 -0
  268. package/script/src/api/exchange/_methods/_base/_nonce.d.ts +3 -2
  269. package/script/src/api/exchange/_methods/_base/_nonce.d.ts.map +1 -1
  270. package/script/src/api/exchange/_methods/_base/_nonce.js +4 -3
  271. package/script/src/api/exchange/_methods/_base/_nonce.js.map +1 -1
  272. package/script/src/api/exchange/_methods/_base/_semaphore.d.ts +7 -6
  273. package/script/src/api/exchange/_methods/_base/_semaphore.d.ts.map +1 -1
  274. package/script/src/api/exchange/_methods/_base/_semaphore.js +35 -50
  275. package/script/src/api/exchange/_methods/_base/_semaphore.js.map +1 -1
  276. package/script/src/api/exchange/_methods/_base/execute.d.ts +14 -3
  277. package/script/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
  278. package/script/src/api/exchange/_methods/_base/execute.js +43 -9
  279. package/script/src/api/exchange/_methods/_base/execute.js.map +1 -1
  280. package/script/src/api/exchange/_methods/batchModify.d.ts +6 -6
  281. package/script/src/api/exchange/_methods/createVault.d.ts +5 -5
  282. package/script/src/api/exchange/_methods/modify.d.ts +5 -5
  283. package/script/src/api/exchange/_methods/order.d.ts +13 -13
  284. package/script/src/api/exchange/_methods/order.d.ts.map +1 -1
  285. package/script/src/api/exchange/_methods/order.js +4 -2
  286. package/script/src/api/exchange/_methods/order.js.map +1 -1
  287. package/script/src/api/exchange/client.d.ts +1 -1
  288. package/script/src/api/exchange/client.d.ts.map +1 -1
  289. package/script/src/api/exchange/client.js.map +1 -1
  290. package/script/src/api/exchange/mod.d.ts +1 -1
  291. package/script/src/api/exchange/mod.d.ts.map +1 -1
  292. package/script/src/api/exchange/mod.js.map +1 -1
  293. package/script/src/api/info/_methods/_base/commonSchemas.d.ts +8 -8
  294. package/script/src/api/info/_methods/frontendOpenOrders.d.ts +3 -3
  295. package/script/src/api/info/_methods/historicalOrders.d.ts +4 -4
  296. package/script/src/api/info/_methods/l3Orders.d.ts +11 -11
  297. package/script/src/api/info/_methods/l4Orders.d.ts +6 -6
  298. package/script/src/api/info/_methods/openOrders.d.ts +3 -3
  299. package/script/src/api/info/_methods/orderStatus.d.ts +5 -5
  300. package/script/src/api/info/_methods/recentTrades.d.ts +2 -2
  301. package/script/src/api/info/_methods/twapHistory.d.ts +4 -4
  302. package/script/src/api/info/_methods/userFills.d.ts +3 -3
  303. package/script/src/api/info/_methods/userFillsByTime.d.ts +4 -4
  304. package/script/src/api/info/_methods/userFunding.d.ts +3 -3
  305. package/script/src/api/info/_methods/userFunding.js +2 -2
  306. package/script/src/api/info/_methods/userFunding.js.map +1 -1
  307. package/script/src/api/info/_methods/userTwapSliceFills.d.ts +4 -4
  308. package/script/src/api/info/_methods/userTwapSliceFillsByTime.d.ts +5 -5
  309. package/script/src/api/info/_methods/webData2.d.ts +9 -9
  310. package/script/src/api/subscription/_methods/assetCtxs.d.ts +2 -0
  311. package/script/src/api/subscription/_methods/assetCtxs.d.ts.map +1 -1
  312. package/script/src/api/subscription/_methods/assetCtxs.js.map +1 -1
  313. package/script/src/api/subscription/_methods/clearinghouseState.d.ts +2 -0
  314. package/script/src/api/subscription/_methods/clearinghouseState.d.ts.map +1 -1
  315. package/script/src/api/subscription/_methods/clearinghouseState.js +2 -0
  316. package/script/src/api/subscription/_methods/clearinghouseState.js.map +1 -1
  317. package/script/src/api/subscription/_methods/explorerBlock.d.ts +2 -0
  318. package/script/src/api/subscription/_methods/explorerBlock.d.ts.map +1 -1
  319. package/script/src/api/subscription/_methods/explorerBlock.js +2 -0
  320. package/script/src/api/subscription/_methods/explorerBlock.js.map +1 -1
  321. package/script/src/api/subscription/_methods/explorerTxs.d.ts +2 -0
  322. package/script/src/api/subscription/_methods/explorerTxs.d.ts.map +1 -1
  323. package/script/src/api/subscription/_methods/explorerTxs.js +2 -0
  324. package/script/src/api/subscription/_methods/explorerTxs.js.map +1 -1
  325. package/script/src/api/subscription/_methods/openOrders.d.ts +5 -5
  326. package/script/src/api/subscription/_methods/orderUpdates.d.ts +4 -4
  327. package/script/src/api/subscription/_methods/trades.d.ts +3 -3
  328. package/script/src/api/subscription/_methods/twapStates.d.ts +9 -4
  329. package/script/src/api/subscription/_methods/twapStates.d.ts.map +1 -1
  330. package/script/src/api/subscription/_methods/twapStates.js +6 -1
  331. package/script/src/api/subscription/_methods/twapStates.js.map +1 -1
  332. package/script/src/api/subscription/_methods/userEvents.d.ts +17 -17
  333. package/script/src/api/subscription/_methods/userFills.d.ts +5 -5
  334. package/script/src/api/subscription/_methods/userHistoricalOrders.d.ts +6 -6
  335. package/script/src/api/subscription/_methods/userTwapHistory.d.ts +6 -6
  336. package/script/src/api/subscription/_methods/userTwapSliceFills.d.ts +6 -6
  337. package/script/src/api/subscription/_methods/webData2.d.ts +11 -11
  338. package/script/src/signing/_privateKeySigner.js +3 -3
  339. package/script/src/signing/_privateKeySigner.js.map +1 -1
  340. package/script/src/signing/mod.js +2 -2
  341. package/script/src/signing/mod.js.map +1 -1
  342. package/src/_dnt.shims.ts +60 -0
  343. package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.ts +633 -0
  344. package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.ts +292 -0
  345. package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.ts +621 -0
  346. package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.ts +1562 -0
  347. package/src/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.ts +327 -0
  348. package/src/deps/jsr.io/@noble/curves/2.0.1/src/utils.ts +306 -0
  349. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/_md.ts +156 -0
  350. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.ts +91 -0
  351. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.ts +94 -0
  352. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.ts +469 -0
  353. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.ts +295 -0
  354. package/src/deps/jsr.io/@noble/hashes/2.0.1/src/utils.ts +340 -0
  355. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.ts +212 -0
  356. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.ts +100 -0
  357. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.ts +104 -0
  358. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.ts +626 -0
  359. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.ts +274 -0
  360. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.ts +391 -0
  361. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.ts +12 -0
  362. package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.ts +233 -0
  363. package/src/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.ts +2196 -0
  364. package/src/deps/jsr.io/@scure/base/2.0.0/index.ts +857 -0
  365. package/src/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.ts +146 -0
  366. package/src/src/api/exchange/_methods/_base/_nonce.ts +3 -2
  367. package/src/src/api/exchange/_methods/_base/_semaphore.ts +34 -59
  368. package/src/src/api/exchange/_methods/_base/execute.ts +60 -12
  369. package/src/src/api/exchange/_methods/order.ts +5 -3
  370. package/src/src/api/exchange/client.ts +5 -1
  371. package/src/src/api/exchange/mod.ts +5 -1
  372. package/src/src/api/info/_methods/userFunding.ts +2 -2
  373. package/src/src/api/subscription/_methods/assetCtxs.ts +2 -0
  374. package/src/src/api/subscription/_methods/clearinghouseState.ts +2 -0
  375. package/src/src/api/subscription/_methods/explorerBlock.ts +2 -0
  376. package/src/src/api/subscription/_methods/explorerTxs.ts +2 -0
  377. package/src/src/api/subscription/_methods/twapStates.ts +9 -1
  378. package/src/src/signing/_privateKeySigner.ts +1 -1
  379. package/src/src/signing/mod.ts +1 -1
  380. package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts +0 -21
  381. package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts.map +0 -1
  382. package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.js +0 -292
  383. package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.js.map +0 -1
  384. package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts +0 -44
  385. package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts.map +0 -1
  386. package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.js +0 -46
  387. package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.js.map +0 -1
  388. package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts +0 -21
  389. package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts.map +0 -1
  390. package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.js +0 -295
  391. package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.js.map +0 -1
  392. package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts +0 -44
  393. package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts.map +0 -1
  394. package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.js +0 -62
  395. package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.js.map +0 -1
  396. package/src/deps/jsr.io/@std/msgpack/1.0.3/decode.ts +0 -391
  397. package/src/deps/jsr.io/@std/msgpack/1.0.3/mod.ts +0 -47
@@ -0,0 +1,621 @@
1
+ /**
2
+ * Utils for modular division and fields.
3
+ * Field over 11 is a finite (Galois) field is integer number operations `mod 11`.
4
+ * There is no division: it is replaced by modular multiplicative inverse.
5
+ * @module
6
+ */
7
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
8
+ import {
9
+ abytes,
10
+ anumber,
11
+ bytesToNumberBE,
12
+ bytesToNumberLE,
13
+ numberToBytesBE,
14
+ numberToBytesLE,
15
+ validateObject,
16
+ } from '../utils.js';
17
+
18
+ // Numbers aren't used in x25519 / x448 builds
19
+ // prettier-ignore
20
+ const _0n = /* @__PURE__ */ BigInt(0), _1n = /* @__PURE__ */ BigInt(1), _2n = /* @__PURE__ */ BigInt(2);
21
+ // prettier-ignore
22
+ const _3n = /* @__PURE__ */ BigInt(3), _4n = /* @__PURE__ */ BigInt(4), _5n = /* @__PURE__ */ BigInt(5);
23
+ // prettier-ignore
24
+ const _7n = /* @__PURE__ */ BigInt(7), _8n = /* @__PURE__ */ BigInt(8), _9n = /* @__PURE__ */ BigInt(9);
25
+ const _16n = /* @__PURE__ */ BigInt(16);
26
+
27
+ // Calculates a modulo b
28
+ export function mod(a: bigint, b: bigint): bigint {
29
+ const result = a % b;
30
+ return result >= _0n ? result : b + result;
31
+ }
32
+ /**
33
+ * Efficiently raise num to power and do modular division.
34
+ * Unsafe in some contexts: uses ladder, so can expose bigint bits.
35
+ * @example
36
+ * pow(2n, 6n, 11n) // 64n % 11n == 9n
37
+ */
38
+ export function pow(num: bigint, power: bigint, modulo: bigint): bigint {
39
+ return FpPow(Field(modulo), num, power);
40
+ }
41
+
42
+ /** Does `x^(2^power)` mod p. `pow2(30, 4)` == `30^(2^4)` */
43
+ export function pow2(x: bigint, power: bigint, modulo: bigint): bigint {
44
+ let res = x;
45
+ while (power-- > _0n) {
46
+ res *= res;
47
+ res %= modulo;
48
+ }
49
+ return res;
50
+ }
51
+
52
+ /**
53
+ * Inverses number over modulo.
54
+ * Implemented using [Euclidean GCD](https://brilliant.org/wiki/extended-euclidean-algorithm/).
55
+ */
56
+ export function invert(number: bigint, modulo: bigint): bigint {
57
+ if (number === _0n) throw new Error('invert: expected non-zero number');
58
+ if (modulo <= _0n) throw new Error('invert: expected positive modulus, got ' + modulo);
59
+ // Fermat's little theorem "CT-like" version inv(n) = n^(m-2) mod m is 30x slower.
60
+ let a = mod(number, modulo);
61
+ let b = modulo;
62
+ // prettier-ignore
63
+ let x = _0n, y = _1n, u = _1n, v = _0n;
64
+ while (a !== _0n) {
65
+ // JIT applies optimization if those two lines follow each other
66
+ const q = b / a;
67
+ const r = b % a;
68
+ const m = x - u * q;
69
+ const n = y - v * q;
70
+ // prettier-ignore
71
+ b = a, a = r, x = u, y = v, u = m, v = n;
72
+ }
73
+ const gcd = b;
74
+ if (gcd !== _1n) throw new Error('invert: does not exist');
75
+ return mod(x, modulo);
76
+ }
77
+
78
+ function assertIsSquare<T>(Fp: IField<T>, root: T, n: T): void {
79
+ if (!Fp.eql(Fp.sqr(root), n)) throw new Error('Cannot find square root');
80
+ }
81
+
82
+ // Not all roots are possible! Example which will throw:
83
+ // const NUM =
84
+ // n = 72057594037927816n;
85
+ // Fp = Field(BigInt('0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab'));
86
+ function sqrt3mod4<T>(Fp: IField<T>, n: T) {
87
+ const p1div4 = (Fp.ORDER + _1n) / _4n;
88
+ const root = Fp.pow(n, p1div4);
89
+ assertIsSquare(Fp, root, n);
90
+ return root;
91
+ }
92
+
93
+ function sqrt5mod8<T>(Fp: IField<T>, n: T) {
94
+ const p5div8 = (Fp.ORDER - _5n) / _8n;
95
+ const n2 = Fp.mul(n, _2n);
96
+ const v = Fp.pow(n2, p5div8);
97
+ const nv = Fp.mul(n, v);
98
+ const i = Fp.mul(Fp.mul(nv, _2n), v);
99
+ const root = Fp.mul(nv, Fp.sub(i, Fp.ONE));
100
+ assertIsSquare(Fp, root, n);
101
+ return root;
102
+ }
103
+
104
+ // Based on RFC9380, Kong algorithm
105
+ // prettier-ignore
106
+ function sqrt9mod16(P: bigint): <T>(Fp: IField<T>, n: T) => T {
107
+ const Fp_ = Field(P);
108
+ const tn = tonelliShanks(P);
109
+ const c1 = tn(Fp_, Fp_.neg(Fp_.ONE));// 1. c1 = sqrt(-1) in F, i.e., (c1^2) == -1 in F
110
+ const c2 = tn(Fp_, c1); // 2. c2 = sqrt(c1) in F, i.e., (c2^2) == c1 in F
111
+ const c3 = tn(Fp_, Fp_.neg(c1)); // 3. c3 = sqrt(-c1) in F, i.e., (c3^2) == -c1 in F
112
+ const c4 = (P + _7n) / _16n; // 4. c4 = (q + 7) / 16 # Integer arithmetic
113
+ return <T>(Fp: IField<T>, n: T) => {
114
+ let tv1 = Fp.pow(n, c4); // 1. tv1 = x^c4
115
+ let tv2 = Fp.mul(tv1, c1); // 2. tv2 = c1 * tv1
116
+ const tv3 = Fp.mul(tv1, c2); // 3. tv3 = c2 * tv1
117
+ const tv4 = Fp.mul(tv1, c3); // 4. tv4 = c3 * tv1
118
+ const e1 = Fp.eql(Fp.sqr(tv2), n); // 5. e1 = (tv2^2) == x
119
+ const e2 = Fp.eql(Fp.sqr(tv3), n); // 6. e2 = (tv3^2) == x
120
+ tv1 = Fp.cmov(tv1, tv2, e1); // 7. tv1 = CMOV(tv1, tv2, e1) # Select tv2 if (tv2^2) == x
121
+ tv2 = Fp.cmov(tv4, tv3, e2); // 8. tv2 = CMOV(tv4, tv3, e2) # Select tv3 if (tv3^2) == x
122
+ const e3 = Fp.eql(Fp.sqr(tv2), n); // 9. e3 = (tv2^2) == x
123
+ const root = Fp.cmov(tv1, tv2, e3);// 10. z = CMOV(tv1, tv2, e3) # Select sqrt from tv1 & tv2
124
+ assertIsSquare(Fp, root, n);
125
+ return root;
126
+ };
127
+ }
128
+
129
+ /**
130
+ * Tonelli-Shanks square root search algorithm.
131
+ * 1. https://eprint.iacr.org/2012/685.pdf (page 12)
132
+ * 2. Square Roots from 1; 24, 51, 10 to Dan Shanks
133
+ * @param P field order
134
+ * @returns function that takes field Fp (created from P) and number n
135
+ */
136
+ export function tonelliShanks(P: bigint): <T>(Fp: IField<T>, n: T) => T {
137
+ // Initialization (precomputation).
138
+ // Caching initialization could boost perf by 7%.
139
+ if (P < _3n) throw new Error('sqrt is not defined for small field');
140
+ // Factor P - 1 = Q * 2^S, where Q is odd
141
+ let Q = P - _1n;
142
+ let S = 0;
143
+ while (Q % _2n === _0n) {
144
+ Q /= _2n;
145
+ S++;
146
+ }
147
+
148
+ // Find the first quadratic non-residue Z >= 2
149
+ let Z = _2n;
150
+ const _Fp = Field(P);
151
+ while (FpLegendre(_Fp, Z) === 1) {
152
+ // Basic primality test for P. After x iterations, chance of
153
+ // not finding quadratic non-residue is 2^x, so 2^1000.
154
+ if (Z++ > 1000) throw new Error('Cannot find square root: probably non-prime P');
155
+ }
156
+ // Fast-path; usually done before Z, but we do "primality test".
157
+ if (S === 1) return sqrt3mod4;
158
+
159
+ // Slow-path
160
+ // TODO: test on Fp2 and others
161
+ let cc = _Fp.pow(Z, Q); // c = z^Q
162
+ const Q1div2 = (Q + _1n) / _2n;
163
+ return function tonelliSlow<T>(Fp: IField<T>, n: T): T {
164
+ if (Fp.is0(n)) return n;
165
+ // Check if n is a quadratic residue using Legendre symbol
166
+ if (FpLegendre(Fp, n) !== 1) throw new Error('Cannot find square root');
167
+
168
+ // Initialize variables for the main loop
169
+ let M = S;
170
+ let c = Fp.mul(Fp.ONE, cc); // c = z^Q, move cc from field _Fp into field Fp
171
+ let t = Fp.pow(n, Q); // t = n^Q, first guess at the fudge factor
172
+ let R = Fp.pow(n, Q1div2); // R = n^((Q+1)/2), first guess at the square root
173
+
174
+ // Main loop
175
+ // while t != 1
176
+ while (!Fp.eql(t, Fp.ONE)) {
177
+ if (Fp.is0(t)) return Fp.ZERO; // if t=0 return R=0
178
+ let i = 1;
179
+
180
+ // Find the smallest i >= 1 such that t^(2^i) ≡ 1 (mod P)
181
+ let t_tmp = Fp.sqr(t); // t^(2^1)
182
+ while (!Fp.eql(t_tmp, Fp.ONE)) {
183
+ i++;
184
+ t_tmp = Fp.sqr(t_tmp); // t^(2^2)...
185
+ if (i === M) throw new Error('Cannot find square root');
186
+ }
187
+
188
+ // Calculate the exponent for b: 2^(M - i - 1)
189
+ const exponent = _1n << BigInt(M - i - 1); // bigint is important
190
+ const b = Fp.pow(c, exponent); // b = 2^(M - i - 1)
191
+
192
+ // Update variables
193
+ M = i;
194
+ c = Fp.sqr(b); // c = b^2
195
+ t = Fp.mul(t, c); // t = (t * b^2)
196
+ R = Fp.mul(R, b); // R = R*b
197
+ }
198
+ return R;
199
+ };
200
+ }
201
+
202
+ /**
203
+ * Square root for a finite field. Will try optimized versions first:
204
+ *
205
+ * 1. P ≡ 3 (mod 4)
206
+ * 2. P ≡ 5 (mod 8)
207
+ * 3. P ≡ 9 (mod 16)
208
+ * 4. Tonelli-Shanks algorithm
209
+ *
210
+ * Different algorithms can give different roots, it is up to user to decide which one they want.
211
+ * For example there is FpSqrtOdd/FpSqrtEven to choice root based on oddness (used for hash-to-curve).
212
+ */
213
+ export function FpSqrt(P: bigint): <T>(Fp: IField<T>, n: T) => T {
214
+ // P ≡ 3 (mod 4) => √n = n^((P+1)/4)
215
+ if (P % _4n === _3n) return sqrt3mod4;
216
+ // P ≡ 5 (mod 8) => Atkin algorithm, page 10 of https://eprint.iacr.org/2012/685.pdf
217
+ if (P % _8n === _5n) return sqrt5mod8;
218
+ // P ≡ 9 (mod 16) => Kong algorithm, page 11 of https://eprint.iacr.org/2012/685.pdf (algorithm 4)
219
+ if (P % _16n === _9n) return sqrt9mod16(P);
220
+ // Tonelli-Shanks algorithm
221
+ return tonelliShanks(P);
222
+ }
223
+
224
+ // Little-endian check for first LE bit (last BE bit);
225
+ export const isNegativeLE = (num: bigint, modulo: bigint): boolean =>
226
+ (mod(num, modulo) & _1n) === _1n;
227
+
228
+ /** Field is not always over prime: for example, Fp2 has ORDER(q)=p^m. */
229
+ export interface IField<T> {
230
+ ORDER: bigint;
231
+ BYTES: number;
232
+ BITS: number;
233
+ isLE: boolean;
234
+ ZERO: T;
235
+ ONE: T;
236
+ // 1-arg
237
+ create: (num: T) => T;
238
+ isValid: (num: T) => boolean;
239
+ is0: (num: T) => boolean;
240
+ isValidNot0: (num: T) => boolean;
241
+ neg(num: T): T;
242
+ inv(num: T): T;
243
+ sqrt(num: T): T;
244
+ sqr(num: T): T;
245
+ // 2-args
246
+ eql(lhs: T, rhs: T): boolean;
247
+ add(lhs: T, rhs: T): T;
248
+ sub(lhs: T, rhs: T): T;
249
+ mul(lhs: T, rhs: T | bigint): T;
250
+ pow(lhs: T, power: bigint): T;
251
+ div(lhs: T, rhs: T | bigint): T;
252
+ // N for NonNormalized (for now)
253
+ addN(lhs: T, rhs: T): T;
254
+ subN(lhs: T, rhs: T): T;
255
+ mulN(lhs: T, rhs: T | bigint): T;
256
+ sqrN(num: T): T;
257
+
258
+ // Optional
259
+ // Should be same as sgn0 function in
260
+ // [RFC9380](https://www.rfc-editor.org/rfc/rfc9380#section-4.1).
261
+ // NOTE: sgn0 is 'negative in LE', which is same as odd. And negative in LE is kinda strange definition anyway.
262
+ isOdd?(num: T): boolean; // Odd instead of even since we have it for Fp2
263
+ // legendre?(num: T): T;
264
+ invertBatch: (lst: T[]) => T[];
265
+ toBytes(num: T): Uint8Array;
266
+ fromBytes(bytes: Uint8Array, skipValidation?: boolean): T;
267
+ // If c is False, CMOV returns a, otherwise it returns b.
268
+ cmov(a: T, b: T, c: boolean): T;
269
+ }
270
+ // prettier-ignore
271
+ const FIELD_FIELDS = [
272
+ 'create', 'isValid', 'is0', 'neg', 'inv', 'sqrt', 'sqr',
273
+ 'eql', 'add', 'sub', 'mul', 'pow', 'div',
274
+ 'addN', 'subN', 'mulN', 'sqrN'
275
+ ] as const;
276
+ export function validateField<T>(field: IField<T>): IField<T> {
277
+ const initial = {
278
+ ORDER: 'bigint',
279
+ BYTES: 'number',
280
+ BITS: 'number',
281
+ } as Record<string, string>;
282
+ const opts = FIELD_FIELDS.reduce((map, val: string) => {
283
+ map[val] = 'function';
284
+ return map;
285
+ }, initial);
286
+ validateObject(field, opts);
287
+ // const max = 16384;
288
+ // if (field.BYTES < 1 || field.BYTES > max) throw new Error('invalid field');
289
+ // if (field.BITS < 1 || field.BITS > 8 * max) throw new Error('invalid field');
290
+ return field;
291
+ }
292
+
293
+ // Generic field functions
294
+
295
+ /**
296
+ * Same as `pow` but for Fp: non-constant-time.
297
+ * Unsafe in some contexts: uses ladder, so can expose bigint bits.
298
+ */
299
+ export function FpPow<T>(Fp: IField<T>, num: T, power: bigint): T {
300
+ if (power < _0n) throw new Error('invalid exponent, negatives unsupported');
301
+ if (power === _0n) return Fp.ONE;
302
+ if (power === _1n) return num;
303
+ let p = Fp.ONE;
304
+ let d = num;
305
+ while (power > _0n) {
306
+ if (power & _1n) p = Fp.mul(p, d);
307
+ d = Fp.sqr(d);
308
+ power >>= _1n;
309
+ }
310
+ return p;
311
+ }
312
+
313
+ /**
314
+ * Efficiently invert an array of Field elements.
315
+ * Exception-free. Will return `undefined` for 0 elements.
316
+ * @param passZero map 0 to 0 (instead of undefined)
317
+ */
318
+ export function FpInvertBatch<T>(Fp: IField<T>, nums: T[], passZero = false): T[] {
319
+ const inverted = new Array(nums.length).fill(passZero ? Fp.ZERO : undefined);
320
+ // Walk from first to last, multiply them by each other MOD p
321
+ const multipliedAcc = nums.reduce((acc, num, i) => {
322
+ if (Fp.is0(num)) return acc;
323
+ inverted[i] = acc;
324
+ return Fp.mul(acc, num);
325
+ }, Fp.ONE);
326
+ // Invert last element
327
+ const invertedAcc = Fp.inv(multipliedAcc);
328
+ // Walk from last to first, multiply them by inverted each other MOD p
329
+ nums.reduceRight((acc, num, i) => {
330
+ if (Fp.is0(num)) return acc;
331
+ inverted[i] = Fp.mul(acc, inverted[i]);
332
+ return Fp.mul(acc, num);
333
+ }, invertedAcc);
334
+ return inverted;
335
+ }
336
+
337
+ // TODO: remove
338
+ export function FpDiv<T>(Fp: IField<T>, lhs: T, rhs: T | bigint): T {
339
+ return Fp.mul(lhs, typeof rhs === 'bigint' ? invert(rhs, Fp.ORDER) : Fp.inv(rhs));
340
+ }
341
+
342
+ /**
343
+ * Legendre symbol.
344
+ * Legendre constant is used to calculate Legendre symbol (a | p)
345
+ * which denotes the value of a^((p-1)/2) (mod p).
346
+ *
347
+ * * (a | p) ≡ 1 if a is a square (mod p), quadratic residue
348
+ * * (a | p) ≡ -1 if a is not a square (mod p), quadratic non residue
349
+ * * (a | p) ≡ 0 if a ≡ 0 (mod p)
350
+ */
351
+ export function FpLegendre<T>(Fp: IField<T>, n: T): -1 | 0 | 1 {
352
+ // We can use 3rd argument as optional cache of this value
353
+ // but seems unneeded for now. The operation is very fast.
354
+ const p1mod2 = (Fp.ORDER - _1n) / _2n;
355
+ const powered = Fp.pow(n, p1mod2);
356
+ const yes = Fp.eql(powered, Fp.ONE);
357
+ const zero = Fp.eql(powered, Fp.ZERO);
358
+ const no = Fp.eql(powered, Fp.neg(Fp.ONE));
359
+ if (!yes && !zero && !no) throw new Error('invalid Legendre symbol result');
360
+ return yes ? 1 : zero ? 0 : -1;
361
+ }
362
+
363
+ // This function returns True whenever the value x is a square in the field F.
364
+ export function FpIsSquare<T>(Fp: IField<T>, n: T): boolean {
365
+ const l = FpLegendre(Fp, n);
366
+ return l === 1;
367
+ }
368
+
369
+ export type NLength = { nByteLength: number; nBitLength: number };
370
+ // CURVE.n lengths
371
+ export function nLength(n: bigint, nBitLength?: number): NLength {
372
+ // Bit size, byte size of CURVE.n
373
+ if (nBitLength !== undefined) anumber(nBitLength);
374
+ const _nBitLength = nBitLength !== undefined ? nBitLength : n.toString(2).length;
375
+ const nByteLength = Math.ceil(_nBitLength / 8);
376
+ return { nBitLength: _nBitLength, nByteLength };
377
+ }
378
+
379
+ type FpField = IField<bigint> & Required<Pick<IField<bigint>, 'isOdd'>>;
380
+ type SqrtFn = (n: bigint) => bigint;
381
+ type FieldOpts = Partial<{
382
+ isLE: boolean;
383
+ BITS: number;
384
+ sqrt: SqrtFn;
385
+ allowedLengths?: readonly number[]; // for P521 (adds padding for smaller sizes)
386
+ modFromBytes: boolean; // bls12-381 requires mod(n) instead of rejecting keys >= n
387
+ }>;
388
+ class _Field implements IField<bigint> {
389
+ readonly ORDER: bigint;
390
+ readonly BITS: number;
391
+ readonly BYTES: number;
392
+ readonly isLE: boolean;
393
+ readonly ZERO = _0n;
394
+ readonly ONE = _1n;
395
+ readonly _lengths?: number[];
396
+ private _sqrt: ReturnType<typeof FpSqrt> | undefined; // cached sqrt
397
+ private readonly _mod?: boolean;
398
+ constructor(ORDER: bigint, opts: FieldOpts = {}) {
399
+ if (ORDER <= _0n) throw new Error('invalid field: expected ORDER > 0, got ' + ORDER);
400
+ let _nbitLength: number | undefined = undefined;
401
+ this.isLE = false;
402
+ if (opts != null && typeof opts === 'object') {
403
+ if (typeof opts.BITS === 'number') _nbitLength = opts.BITS;
404
+ if (typeof opts.sqrt === 'function') this.sqrt = opts.sqrt;
405
+ if (typeof opts.isLE === 'boolean') this.isLE = opts.isLE;
406
+ if (opts.allowedLengths) this._lengths = opts.allowedLengths?.slice();
407
+ if (typeof opts.modFromBytes === 'boolean') this._mod = opts.modFromBytes;
408
+ }
409
+ const { nBitLength, nByteLength } = nLength(ORDER, _nbitLength);
410
+ if (nByteLength > 2048) throw new Error('invalid field: expected ORDER of <= 2048 bytes');
411
+ this.ORDER = ORDER;
412
+ this.BITS = nBitLength;
413
+ this.BYTES = nByteLength;
414
+ this._sqrt = undefined;
415
+ Object.preventExtensions(this);
416
+ }
417
+
418
+ create(num: bigint) {
419
+ return mod(num, this.ORDER);
420
+ }
421
+ isValid(num: bigint) {
422
+ if (typeof num !== 'bigint')
423
+ throw new Error('invalid field element: expected bigint, got ' + typeof num);
424
+ return _0n <= num && num < this.ORDER; // 0 is valid element, but it's not invertible
425
+ }
426
+ is0(num: bigint) {
427
+ return num === _0n;
428
+ }
429
+ // is valid and invertible
430
+ isValidNot0(num: bigint) {
431
+ return !this.is0(num) && this.isValid(num);
432
+ }
433
+ isOdd(num: bigint) {
434
+ return (num & _1n) === _1n;
435
+ }
436
+ neg(num: bigint) {
437
+ return mod(-num, this.ORDER);
438
+ }
439
+ eql(lhs: bigint, rhs: bigint) {
440
+ return lhs === rhs;
441
+ }
442
+
443
+ sqr(num: bigint) {
444
+ return mod(num * num, this.ORDER);
445
+ }
446
+ add(lhs: bigint, rhs: bigint) {
447
+ return mod(lhs + rhs, this.ORDER);
448
+ }
449
+ sub(lhs: bigint, rhs: bigint) {
450
+ return mod(lhs - rhs, this.ORDER);
451
+ }
452
+ mul(lhs: bigint, rhs: bigint) {
453
+ return mod(lhs * rhs, this.ORDER);
454
+ }
455
+ pow(num: bigint, power: bigint): bigint {
456
+ return FpPow(this, num, power);
457
+ }
458
+ div(lhs: bigint, rhs: bigint) {
459
+ return mod(lhs * invert(rhs, this.ORDER), this.ORDER);
460
+ }
461
+
462
+ // Same as above, but doesn't normalize
463
+ sqrN(num: bigint) {
464
+ return num * num;
465
+ }
466
+ addN(lhs: bigint, rhs: bigint) {
467
+ return lhs + rhs;
468
+ }
469
+ subN(lhs: bigint, rhs: bigint) {
470
+ return lhs - rhs;
471
+ }
472
+ mulN(lhs: bigint, rhs: bigint) {
473
+ return lhs * rhs;
474
+ }
475
+
476
+ inv(num: bigint) {
477
+ return invert(num, this.ORDER);
478
+ }
479
+ sqrt(num: bigint): bigint {
480
+ // Caching _sqrt speeds up sqrt9mod16 by 5x and tonneli-shanks by 10%
481
+ if (!this._sqrt) this._sqrt = FpSqrt(this.ORDER);
482
+ return this._sqrt(this, num);
483
+ }
484
+ toBytes(num: bigint) {
485
+ return this.isLE ? numberToBytesLE(num, this.BYTES) : numberToBytesBE(num, this.BYTES);
486
+ }
487
+ fromBytes(bytes: Uint8Array, skipValidation = false) {
488
+ abytes(bytes);
489
+ const { _lengths: allowedLengths, BYTES, isLE, ORDER, _mod: modFromBytes } = this;
490
+ if (allowedLengths) {
491
+ if (!allowedLengths.includes(bytes.length) || bytes.length > BYTES) {
492
+ throw new Error(
493
+ 'Field.fromBytes: expected ' + allowedLengths + ' bytes, got ' + bytes.length
494
+ );
495
+ }
496
+ const padded = new Uint8Array(BYTES);
497
+ // isLE add 0 to right, !isLE to the left.
498
+ padded.set(bytes, isLE ? 0 : padded.length - bytes.length);
499
+ bytes = padded;
500
+ }
501
+ if (bytes.length !== BYTES)
502
+ throw new Error('Field.fromBytes: expected ' + BYTES + ' bytes, got ' + bytes.length);
503
+ let scalar = isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
504
+ if (modFromBytes) scalar = mod(scalar, ORDER);
505
+ if (!skipValidation)
506
+ if (!this.isValid(scalar))
507
+ throw new Error('invalid field element: outside of range 0..ORDER');
508
+ // NOTE: we don't validate scalar here, please use isValid. This done such way because some
509
+ // protocol may allow non-reduced scalar that reduced later or changed some other way.
510
+ return scalar;
511
+ }
512
+ // TODO: we don't need it here, move out to separate fn
513
+ invertBatch(lst: bigint[]): bigint[] {
514
+ return FpInvertBatch(this, lst);
515
+ }
516
+ // We can't move this out because Fp6, Fp12 implement it
517
+ // and it's unclear what to return in there.
518
+ cmov(a: bigint, b: bigint, condition: boolean) {
519
+ return condition ? b : a;
520
+ }
521
+ }
522
+
523
+ /**
524
+ * Creates a finite field. Major performance optimizations:
525
+ * * 1. Denormalized operations like mulN instead of mul.
526
+ * * 2. Identical object shape: never add or remove keys.
527
+ * * 3. `Object.freeze`.
528
+ * Fragile: always run a benchmark on a change.
529
+ * Security note: operations don't check 'isValid' for all elements for performance reasons,
530
+ * it is caller responsibility to check this.
531
+ * This is low-level code, please make sure you know what you're doing.
532
+ *
533
+ * Note about field properties:
534
+ * * CHARACTERISTIC p = prime number, number of elements in main subgroup.
535
+ * * ORDER q = similar to cofactor in curves, may be composite `q = p^m`.
536
+ *
537
+ * @param ORDER field order, probably prime, or could be composite
538
+ * @param bitLen how many bits the field consumes
539
+ * @param isLE (default: false) if encoding / decoding should be in little-endian
540
+ * @param redef optional faster redefinitions of sqrt and other methods
541
+ */
542
+ export function Field(ORDER: bigint, opts: FieldOpts = {}): Readonly<FpField> {
543
+ return new _Field(ORDER, opts);
544
+ }
545
+
546
+ // Generic random scalar, we can do same for other fields if via Fp2.mul(Fp2.ONE, Fp2.random)?
547
+ // This allows unsafe methods like ignore bias or zero. These unsafe, but often used in different protocols (if deterministic RNG).
548
+ // which mean we cannot force this via opts.
549
+ // Not sure what to do with randomBytes, we can accept it inside opts if wanted.
550
+ // Probably need to export getMinHashLength somewhere?
551
+ // random(bytes?: Uint8Array, unsafeAllowZero = false, unsafeAllowBias = false) {
552
+ // const LEN = !unsafeAllowBias ? getMinHashLength(ORDER) : BYTES;
553
+ // if (bytes === undefined) bytes = randomBytes(LEN); // _opts.randomBytes?
554
+ // const num = isLE ? bytesToNumberLE(bytes) : bytesToNumberBE(bytes);
555
+ // // `mod(x, 11)` can sometimes produce 0. `mod(x, 10) + 1` is the same, but no 0
556
+ // const reduced = unsafeAllowZero ? mod(num, ORDER) : mod(num, ORDER - _1n) + _1n;
557
+ // return reduced;
558
+ // },
559
+
560
+ export function FpSqrtOdd<T>(Fp: IField<T>, elm: T): T {
561
+ if (!Fp.isOdd) throw new Error("Field doesn't have isOdd");
562
+ const root = Fp.sqrt(elm);
563
+ return Fp.isOdd(root) ? root : Fp.neg(root);
564
+ }
565
+
566
+ export function FpSqrtEven<T>(Fp: IField<T>, elm: T): T {
567
+ if (!Fp.isOdd) throw new Error("Field doesn't have isOdd");
568
+ const root = Fp.sqrt(elm);
569
+ return Fp.isOdd(root) ? Fp.neg(root) : root;
570
+ }
571
+
572
+ /**
573
+ * Returns total number of bytes consumed by the field element.
574
+ * For example, 32 bytes for usual 256-bit weierstrass curve.
575
+ * @param fieldOrder number of field elements, usually CURVE.n
576
+ * @returns byte length of field
577
+ */
578
+ export function getFieldBytesLength(fieldOrder: bigint): number {
579
+ if (typeof fieldOrder !== 'bigint') throw new Error('field order must be bigint');
580
+ const bitLength = fieldOrder.toString(2).length;
581
+ return Math.ceil(bitLength / 8);
582
+ }
583
+
584
+ /**
585
+ * Returns minimal amount of bytes that can be safely reduced
586
+ * by field order.
587
+ * Should be 2^-128 for 128-bit curve such as P256.
588
+ * @param fieldOrder number of field elements, usually CURVE.n
589
+ * @returns byte length of target hash
590
+ */
591
+ export function getMinHashLength(fieldOrder: bigint): number {
592
+ const length = getFieldBytesLength(fieldOrder);
593
+ return length + Math.ceil(length / 2);
594
+ }
595
+
596
+ /**
597
+ * "Constant-time" private key generation utility.
598
+ * Can take (n + n/2) or more bytes of uniform input e.g. from CSPRNG or KDF
599
+ * and convert them into private scalar, with the modulo bias being negligible.
600
+ * Needs at least 48 bytes of input for 32-byte private key.
601
+ * https://research.kudelskisecurity.com/2020/07/28/the-definitive-guide-to-modulo-bias-and-how-to-avoid-it/
602
+ * FIPS 186-5, A.2 https://csrc.nist.gov/publications/detail/fips/186/5/final
603
+ * RFC 9380, https://www.rfc-editor.org/rfc/rfc9380#section-5
604
+ * @param hash hash output from SHA3 or a similar function
605
+ * @param groupOrder size of subgroup - (e.g. secp256k1.Point.Fn.ORDER)
606
+ * @param isLE interpret hash bytes as LE num
607
+ * @returns valid private scalar
608
+ */
609
+ export function mapHashToField(key: Uint8Array, fieldOrder: bigint, isLE = false): Uint8Array {
610
+ abytes(key);
611
+ const len = key.length;
612
+ const fieldLen = getFieldBytesLength(fieldOrder);
613
+ const minLen = getMinHashLength(fieldOrder);
614
+ // No small numbers: need to understand bias story. No huge numbers: easier to detect JS timings.
615
+ if (len < 16 || len < minLen || len > 1024)
616
+ throw new Error('expected ' + minLen + '-1024 bytes of input, got ' + len);
617
+ const num = isLE ? bytesToNumberLE(key) : bytesToNumberBE(key);
618
+ // `mod(x, 11)` can sometimes produce 0. `mod(x, 10) + 1` is the same, but no 0
619
+ const reduced = mod(num, fieldOrder - _1n) + _1n;
620
+ return isLE ? numberToBytesLE(reduced, fieldLen) : numberToBytesBE(reduced, fieldLen);
621
+ }