@layerswap/widget 0.1.4 → 0.1.14

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 (267) hide show
  1. package/README.md +78 -3
  2. package/dist/Models/Theme.d.ts +7 -6
  3. package/dist/Models/Theme.js +7 -7
  4. package/dist/Models/WalletProvider.d.ts +0 -4
  5. package/dist/Models/WalletProvider.js +2 -0
  6. package/dist/components/Buttons/copyButton.js +4 -3
  7. package/dist/components/ColorSchema.js +79 -45
  8. package/dist/components/Common/AddressIcon.js +1 -0
  9. package/dist/components/Common/AverageCompletionTime.js +1 -1
  10. package/dist/components/Common/CountDownTimer.js +2 -2
  11. package/dist/components/Common/FormattedAverageCompletionTime.js +1 -1
  12. package/dist/components/HeaderWithMenu/index.js +1 -8
  13. package/dist/components/Input/Address/AddressNote.js +3 -2
  14. package/dist/components/Input/Address/AddressPicker/AddressWithIcon.js +2 -2
  15. package/dist/components/Input/Address/AddressPicker/ConnectedWallets/ConnectWalletButton.js +12 -5
  16. package/dist/components/Input/Address/AddressPicker/ExchangeNote.d.ts +1 -1
  17. package/dist/components/Input/Address/AddressPicker/ExchangeNote.js +1 -1
  18. package/dist/components/Input/RouteIcon.js +1 -1
  19. package/dist/components/LayerswapMenu/MenuList.js +2 -56
  20. package/dist/components/Pages/404/index.js +1 -0
  21. package/dist/components/Pages/Auth/Steps/CodeStep/VerifyEmailCode.js +1 -0
  22. package/dist/components/Pages/Auth/index.d.ts +1 -1
  23. package/dist/components/Pages/Auth/index.js +3 -2
  24. package/dist/components/Pages/Campaigns/Details/Leaderboard.js +1 -0
  25. package/dist/components/Pages/Campaigns/Details/index.d.ts +1 -1
  26. package/dist/components/Pages/Campaigns/Details/index.js +3 -2
  27. package/dist/components/Pages/Campaigns/index.d.ts +1 -1
  28. package/dist/components/Pages/Campaigns/index.js +3 -2
  29. package/dist/components/Pages/Maintanance/index.js +1 -0
  30. package/dist/components/Pages/NoCookies/index.js +1 -0
  31. package/dist/components/Pages/SwapHistory/History.js +1 -2
  32. package/dist/components/Pages/SwapHistory/index.d.ts +1 -1
  33. package/dist/components/Pages/SwapHistory/index.js +4 -3
  34. package/dist/components/Pages/SwapPages/Form/FeeDetails/Campaign.js +1 -0
  35. package/dist/components/Pages/SwapPages/Form/Form.js +1 -4
  36. package/dist/components/Pages/SwapPages/Form/SecondaryComponents/ValidationError.js +1 -1
  37. package/dist/components/Pages/SwapPages/Form/Select/Popover/PopoverSelect.js +1 -1
  38. package/dist/components/Pages/SwapPages/Form/index.js +1 -0
  39. package/dist/components/Pages/SwapPages/Withdraw/Coinbase/Carousel.js +8 -6
  40. package/dist/components/Pages/SwapPages/Withdraw/Processing/Processing.js +2 -2
  41. package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.d.ts +0 -4
  42. package/dist/components/Pages/SwapPages/Withdraw/Wallet/FuelWalletWithdrawal.js +159 -125
  43. package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.d.ts +0 -4
  44. package/dist/components/Pages/SwapPages/Withdraw/Wallet/ImtblxWalletWithdrawStep.js +69 -51
  45. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.d.ts +0 -8
  46. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/ActivationTokentPicker.js +87 -45
  47. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.d.ts +0 -40
  48. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/hooks.js +73 -46
  49. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.d.ts +0 -4
  50. package/dist/components/Pages/SwapPages/Withdraw/Wallet/Loopring/index.js +175 -128
  51. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.d.ts +0 -7
  52. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/index.js +138 -116
  53. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.d.ts +0 -8
  54. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SVMWalletWithdraw/transactionSender.js +96 -75
  55. package/dist/components/Pages/SwapPages/Withdraw/Wallet/SophonWalletWithdraw.js +2 -2
  56. package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.d.ts +0 -4
  57. package/dist/components/Pages/SwapPages/Withdraw/Wallet/StarknetWalletWithdraw.js +88 -71
  58. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.d.ts +0 -4
  59. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TonWalletWithdraw.js +146 -136
  60. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.d.ts +0 -4
  61. package/dist/components/Pages/SwapPages/Withdraw/Wallet/TronWalletWithdraw.js +120 -99
  62. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/TransferToken.js +3 -3
  63. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/buttons.js +1 -0
  64. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/index.js +1 -1
  65. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransfer/transactionMessage.js +2 -2
  66. package/dist/components/Pages/SwapPages/Withdraw/Wallet/WalletTransferContent.js +101 -33
  67. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.d.ts +0 -4
  68. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Evm.js +60 -55
  69. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.d.ts +0 -4
  70. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/Starknet.js +71 -55
  71. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/buttons.js +1 -0
  72. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.d.ts +0 -4
  73. package/dist/components/Pages/SwapPages/Withdraw/Wallet/paradex/index.js +56 -52
  74. package/dist/components/Pages/SwapPages/Withdraw/index.d.ts +1 -1
  75. package/dist/components/Pages/SwapPages/Withdraw/index.js +3 -2
  76. package/dist/components/Wallet/WalletModal/Connector.js +1 -1
  77. package/dist/components/Wallet/WalletProviders/FuelProvider.d.ts +0 -5
  78. package/dist/components/Wallet/WalletProviders/FuelProvider.js +25 -20
  79. package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.d.ts +0 -5
  80. package/dist/components/Wallet/WalletProviders/ImtblPassportProvider.js +39 -36
  81. package/dist/components/Wallet/WalletProviders/SolanaProvider.d.ts +0 -5
  82. package/dist/components/Wallet/WalletProviders/SolanaProvider.js +49 -38
  83. package/dist/components/Wallet/WalletProviders/StarknetProvider.d.ts +0 -5
  84. package/dist/components/Wallet/WalletProviders/StarknetProvider.js +112 -117
  85. package/dist/components/Wallet/WalletProviders/TonConnectProvider.d.ts +0 -6
  86. package/dist/components/Wallet/WalletProviders/TonConnectProvider.js +58 -50
  87. package/dist/components/Wallet/WalletProviders/TronProvider.d.ts +0 -3
  88. package/dist/components/Wallet/WalletProviders/TronProvider.js +23 -15
  89. package/dist/components/Wallet/WalletProviders/Wagmi.d.ts +1 -1
  90. package/dist/components/Wallet/WalletProviders/Wagmi.js +20 -10
  91. package/dist/components/Wallet/WalletProviders/index.js +13 -6
  92. package/dist/components/Widget/Footer.d.ts +2 -1
  93. package/dist/components/Widget/Footer.js +13 -4
  94. package/dist/components/Widget/Index.d.ts +1 -1
  95. package/dist/components/Widget/Index.js +1 -1
  96. package/dist/components/WidgetLoading.d.ts +1 -0
  97. package/dist/components/WidgetLoading.js +5 -0
  98. package/dist/components/Wizard/Wizard.js +1 -1
  99. package/dist/components/shadcn/command.js +1 -1
  100. package/dist/components/themeWrapper.js +3 -2
  101. package/dist/context/{LayerswapContext.d.ts → LayerswapProvider.d.ts} +3 -8
  102. package/dist/context/{LayerswapContext.js → LayerswapProvider.js} +8 -9
  103. package/dist/context/authContext.js +1 -0
  104. package/dist/context/walletHooksProvider.js +1 -0
  105. package/dist/hooks/useWallet.js +10 -14
  106. package/dist/index.css +1 -1
  107. package/dist/index.d.ts +3 -5
  108. package/dist/index.js +2 -4
  109. package/dist/index.mjs +19 -0
  110. package/dist/lib/AppSettings.d.ts +7 -3
  111. package/dist/lib/AppSettings.js +8 -7
  112. package/dist/lib/address/formatter/index.js +8 -9
  113. package/dist/lib/address/validator/index.js +18 -20
  114. package/dist/lib/axiosInterceptor.js +1 -2
  115. package/dist/lib/balances/balanceResolver.js +16 -16
  116. package/dist/lib/balances/providers/evmBalanceProvider.js +3 -3
  117. package/dist/lib/balances/providers/loopringBalanceProvider.d.ts +0 -6
  118. package/dist/lib/balances/providers/loopringBalanceProvider.js +56 -43
  119. package/dist/lib/balances/providers/paradexBalanceProvider.d.ts +0 -6
  120. package/dist/lib/balances/providers/paradexBalanceProvider.js +42 -42
  121. package/dist/lib/balances/providers/solanaBalanceProvider.d.ts +0 -6
  122. package/dist/lib/balances/providers/solanaBalanceProvider.js +70 -71
  123. package/dist/lib/balances/providers/starknetBalanceProvider.d.ts +0 -6
  124. package/dist/lib/balances/providers/starknetBalanceProvider.js +48 -45
  125. package/dist/lib/balances/providers/tonBalanceProvider.d.ts +0 -18
  126. package/dist/lib/balances/providers/tonBalanceProvider.js +104 -100
  127. package/dist/lib/balances/providers/tronBalanceResolver.js +2 -3
  128. package/dist/lib/fuels/common/FakeAccount.d.ts +0 -24
  129. package/dist/lib/fuels/common/FakeAccount.js +58 -36
  130. package/dist/lib/fuels/common/PredicateConnector.d.ts +0 -54
  131. package/dist/lib/fuels/common/PredicateConnector.js +292 -205
  132. package/dist/lib/fuels/common/PredicateFactory.d.ts +0 -29
  133. package/dist/lib/fuels/common/PredicateFactory.js +123 -76
  134. package/dist/lib/fuels/common/PredicateWalletAdapter.d.ts +0 -17
  135. package/dist/lib/fuels/common/PredicateWalletAdapter.js +44 -29
  136. package/dist/lib/fuels/common/index.d.ts +0 -4
  137. package/dist/lib/fuels/common/index.js +4 -4
  138. package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.d.ts +0 -51
  139. package/dist/lib/fuels/connectors/fuel-wallet/FuelWalletConnector.js +268 -234
  140. package/dist/lib/fuels/connectors/fuel-wallet/index.d.ts +0 -2
  141. package/dist/lib/fuels/connectors/fuel-wallet/index.js +2 -2
  142. package/dist/lib/fuels/connectors/fuel-wallet/types.d.ts +0 -50
  143. package/dist/lib/fuels/connectors/fuel-wallet/types.js +53 -9
  144. package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.d.ts +0 -7
  145. package/dist/lib/fuels/connectors/fuelet-wallet/FueletWalletConnector.js +20 -19
  146. package/dist/lib/fuels/connectors/fuelet-wallet/index.d.ts +0 -1
  147. package/dist/lib/fuels/connectors/fuelet-wallet/index.js +1 -1
  148. package/dist/lib/gases/gasResolver.d.ts +1 -1
  149. package/dist/lib/gases/gasResolver.js +10 -10
  150. package/dist/lib/gases/providers/evmGasProvider.js +5 -4
  151. package/dist/lib/gases/providers/loopringGasProvider.d.ts +0 -6
  152. package/dist/lib/gases/providers/loopringGasProvider.js +27 -24
  153. package/dist/lib/gases/providers/solanaGasProvider.d.ts +0 -7
  154. package/dist/lib/gases/providers/solanaGasProvider.js +32 -31
  155. package/dist/lib/gases/providers/starknetGasProvider.d.ts +0 -7
  156. package/dist/lib/gases/providers/starknetGasProvider.js +34 -33
  157. package/dist/lib/imtbl.d.ts +0 -69
  158. package/dist/lib/imtbl.js +63 -60
  159. package/dist/lib/internalApiClient.d.ts +0 -2
  160. package/dist/lib/internalApiClient.js +1 -4
  161. package/dist/lib/layerSwapApiClient.js +3 -3
  162. package/dist/lib/logError.js +2 -2
  163. package/dist/lib/nft/nftBalanceResolver.js +1 -2
  164. package/dist/lib/nft/providers/starknetNftProvider.d.ts +0 -6
  165. package/dist/lib/nft/providers/starknetNftProvider.js +49 -50
  166. package/dist/lib/wallets/connectors/EthereumProvider.d.ts +2 -2
  167. package/dist/lib/wallets/connectors/useSyncProviders/store.d.ts +1 -4
  168. package/dist/lib/wallets/fuel/Bako.d.ts +0 -15
  169. package/dist/lib/wallets/fuel/Bako.js +34 -29
  170. package/dist/lib/wallets/fuel/Basko.d.ts +0 -15
  171. package/dist/lib/wallets/fuel/Basko.js +34 -29
  172. package/dist/lib/wallets/fuel/useFuel.d.ts +0 -2
  173. package/dist/lib/wallets/fuel/useFuel.js +211 -192
  174. package/dist/lib/wallets/imtblX/useImtblX.d.ts +0 -2
  175. package/dist/lib/wallets/imtblX/useImtblX.js +87 -87
  176. package/dist/lib/wallets/paradex/Authorize/Ethereum.d.ts +0 -2
  177. package/dist/lib/wallets/paradex/Authorize/Ethereum.js +24 -23
  178. package/dist/lib/wallets/paradex/Authorize/Starknet.d.ts +0 -2
  179. package/dist/lib/wallets/paradex/Authorize/Starknet.js +14 -13
  180. package/dist/lib/wallets/paradex/lib/account.d.ts +0 -28
  181. package/dist/lib/wallets/paradex/lib/account.js +102 -53
  182. package/dist/lib/wallets/paradex/lib/index.d.ts +0 -24
  183. package/dist/lib/wallets/paradex/lib/index.js +20 -20
  184. package/dist/lib/wallets/paradex/lib/paraclear-provider.d.ts +0 -6
  185. package/dist/lib/wallets/paradex/lib/paraclear-provider.js +13 -9
  186. package/dist/lib/wallets/paradex/lib/paraclear.d.ts +0 -137
  187. package/dist/lib/wallets/paradex/lib/paraclear.js +258 -131
  188. package/dist/lib/wallets/paradex/lib/starknet-account-support.d.ts +0 -22
  189. package/dist/lib/wallets/paradex/lib/starknet-account-support.js +296 -220
  190. package/dist/lib/wallets/paradex/lib/starknet-signer.d.ts +0 -15
  191. package/dist/lib/wallets/paradex/lib/starknet-signer.js +120 -94
  192. package/dist/lib/wallets/paradex/useParadex.d.ts +0 -7
  193. package/dist/lib/wallets/paradex/useParadex.js +197 -194
  194. package/dist/lib/wallets/solana/transactionBuilder.d.ts +0 -4
  195. package/dist/lib/wallets/solana/transactionBuilder.js +63 -39
  196. package/dist/lib/wallets/solana/useSVM.d.ts +0 -5
  197. package/dist/lib/wallets/solana/useSVM.js +139 -142
  198. package/dist/lib/wallets/starknet/useStarknet.d.ts +0 -2
  199. package/dist/lib/wallets/starknet/useStarknet.js +139 -139
  200. package/dist/lib/wallets/ton/client.d.ts +0 -3
  201. package/dist/lib/wallets/ton/client.js +7 -7
  202. package/dist/lib/wallets/ton/useTON.d.ts +0 -2
  203. package/dist/lib/wallets/ton/useTON.js +121 -122
  204. package/dist/lib/wallets/tron/connectors/bitkeep.d.ts +0 -61
  205. package/dist/lib/wallets/tron/connectors/bitkeep.js +326 -303
  206. package/dist/lib/wallets/tron/connectors/index.d.ts +0 -4
  207. package/dist/lib/wallets/tron/connectors/index.js +4 -4
  208. package/dist/lib/wallets/tron/connectors/okxWallet.d.ts +0 -66
  209. package/dist/lib/wallets/tron/connectors/okxWallet.js +364 -336
  210. package/dist/lib/wallets/tron/connectors/tokenPocket.d.ts +0 -72
  211. package/dist/lib/wallets/tron/connectors/tokenPocket.js +337 -308
  212. package/dist/lib/wallets/tron/connectors/tronLink/index.d.ts +0 -102
  213. package/dist/lib/wallets/tron/connectors/tronLink/index.js +560 -520
  214. package/dist/lib/wallets/tron/connectors/tronLink/types.d.ts +0 -56
  215. package/dist/lib/wallets/tron/connectors/tronLink/types.js +53 -1
  216. package/dist/lib/wallets/tron/connectors/tronLink/utils.d.ts +0 -14
  217. package/dist/lib/wallets/tron/connectors/tronLink/utils.js +64 -61
  218. package/dist/lib/wallets/tron/useTron.d.ts +0 -2
  219. package/dist/lib/wallets/tron/useTron.js +111 -111
  220. package/dist/lib/wallets/utils/resolveWalletIcon.js +1 -0
  221. package/package.json +26 -77
  222. package/dist/hooks/useCopyClipboard.d.ts +0 -1
  223. package/dist/hooks/useCopyClipboard.js +0 -21
  224. package/dist/index.cjs +0 -125
  225. package/dist/lib/abis/ERC20.json +0 -258
  226. package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.d.ts +0 -42
  227. package/dist/lib/fuels/connectors/walletConnect/WalletConnectConnector.js +0 -357
  228. package/dist/lib/fuels/connectors/walletConnect/constants.d.ts +0 -6
  229. package/dist/lib/fuels/connectors/walletConnect/constants.js +0 -7
  230. package/dist/lib/fuels/connectors/walletConnect/index.d.ts +0 -3
  231. package/dist/lib/fuels/connectors/walletConnect/index.js +0 -3
  232. package/dist/lib/fuels/connectors/walletConnect/types.d.ts +0 -12
  233. package/dist/lib/fuels/connectors/walletConnect/types.js +0 -1
  234. package/dist/lib/fuels/connectors/walletConnect/utils/index.d.ts +0 -1
  235. package/dist/lib/fuels/connectors/walletConnect/utils/index.js +0 -1
  236. package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.d.ts +0 -2
  237. package/dist/lib/fuels/connectors/walletConnect/utils/subscribeAndEnforceChain.js +0 -39
  238. package/dist/lib/fuels/connectors/walletConnect/web3Modal.d.ts +0 -10
  239. package/dist/lib/fuels/connectors/walletConnect/web3Modal.js +0 -38
  240. package/dist/lib/loopring/LoopringAPI.d.ts +0 -12
  241. package/dist/lib/loopring/LoopringAPI.js +0 -13
  242. package/dist/lib/loopring/defs.d.ts +0 -425
  243. package/dist/lib/loopring/defs.js +0 -217
  244. package/dist/lib/loopring/eddsa.d.ts +0 -29
  245. package/dist/lib/loopring/eddsa.js +0 -208
  246. package/dist/lib/loopring/field.d.ts +0 -17
  247. package/dist/lib/loopring/field.js +0 -61
  248. package/dist/lib/loopring/formatter.d.ts +0 -137
  249. package/dist/lib/loopring/formatter.js +0 -516
  250. package/dist/lib/loopring/helpers.d.ts +0 -36
  251. package/dist/lib/loopring/helpers.js +0 -140
  252. package/dist/lib/loopring/jubjub.d.ts +0 -19
  253. package/dist/lib/loopring/jubjub.js +0 -79
  254. package/dist/lib/loopring/permutation.d.ts +0 -22
  255. package/dist/lib/loopring/permutation.js +0 -198
  256. package/dist/lib/loopring/poseidon/EDDSAUtil.d.ts +0 -14
  257. package/dist/lib/loopring/poseidon/EDDSAUtil.js +0 -61
  258. package/dist/lib/loopring/poseidon/babyJub.d.ts +0 -6
  259. package/dist/lib/loopring/poseidon/babyJub.js +0 -51
  260. package/dist/lib/loopring/poseidon/eddsa.d.ts +0 -29
  261. package/dist/lib/loopring/poseidon/eddsa.js +0 -210
  262. package/dist/lib/loopring/utils.d.ts +0 -76
  263. package/dist/lib/loopring/utils.js +0 -230
  264. package/dist/styles/dialog-transition.css +0 -28
  265. package/dist/styles/globals.css +0 -372
  266. package/dist/styles/manual-trasnfer-svg.css +0 -299
  267. package/dist/styles/vaul.css +0 -256
@@ -1,29 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- import { FQ } from "./field";
3
- import { Point } from "./jubjub";
4
- export declare class Signature {
5
- R: Point;
6
- s: FQ;
7
- constructor(R: Point, s: FQ);
8
- toStr(): string;
9
- }
10
- export declare class SignedMessage {
11
- A: Point;
12
- sig: Signature;
13
- msg: BigNumber;
14
- constructor(A: Point, sig: Signature, msg: BigNumber);
15
- toStr(): string;
16
- }
17
- export declare class SignatureScheme {
18
- static to_bytes(arg: BigNumber): number[];
19
- static prehash_message(M: BigNumber): BigNumber;
20
- static hash_secret_python(k: FQ, arg: BigNumber): BigNumber;
21
- static B(): Point;
22
- static sign(msg: BigNumber, key: FQ, B: Point): SignedMessage;
23
- static as_scalar(point: Point): BigNumber[];
24
- static hash_public(R: Point, A: Point, M: BigNumber): any;
25
- }
26
- export declare function bnToBuf(bn: string): number[];
27
- export declare function bnToBufWithFixedLength(bn: string, outputLength: number): number[];
28
- export declare function bufToBn(buf: any): bigint;
29
- export declare function bytesToHexString(bytes: any): any;
@@ -1,208 +0,0 @@
1
- /*
2
- Implements Pure-EdDSA and Hash-EdDSA
3
-
4
- The signer has two secret values:
5
-
6
- * k = Secret key
7
- * r = Per-(message,key) nonce
8
-
9
- The signer provides a signature consiting of two values:
10
-
11
- * R = Point, image of `r*B`
12
- * s = Image of `r + (k*t)`
13
-
14
- The signer provides the verifier with their public key:
15
-
16
- * A = k*B
17
-
18
- Both the verifier and the signer calculate the common reference string:
19
-
20
- * t = H(R, A, M)
21
-
22
- The nonce `r` is secret, and protects the value `s` from revealing the
23
- signers secret key.
24
-
25
- For Hash-EdDSA, the message `M` is compressed before H(R,A,M)
26
-
27
- For further information see: https://ed2519.cr.yp.to/eddsa-20150704.pdf
28
- */
29
- import { BigNumber } from "ethers";
30
- import { field, FQ } from "./field";
31
- import { jubjub, Point } from "./jubjub";
32
- import { sha512 } from "js-sha512";
33
- import { permunation, PoseidonParams } from "./permutation";
34
- export class Signature {
35
- constructor(R, s) {
36
- this.R = R;
37
- this.s = s;
38
- }
39
- toStr() {
40
- return `${this.R.x.n} ${this.R.y.n} ${this.s.n}`;
41
- }
42
- }
43
- export class SignedMessage {
44
- constructor(A, sig, msg) {
45
- this.A = A;
46
- this.sig = sig;
47
- this.msg = msg;
48
- }
49
- toStr() {
50
- return `${this.A.x.n} ${this.A.y.n} ${this.sig.toStr()} ${this.msg.toString()}`;
51
- }
52
- }
53
- export class SignatureScheme {
54
- static to_bytes(arg) {
55
- const outputLength = 32;
56
- let bitIntDataItems = bnToBuf(arg.toString());
57
- const more = outputLength - bitIntDataItems.length;
58
- if (more > 0) {
59
- for (let i = 0; i < more; i++) {
60
- bitIntDataItems = [0].concat(bitIntDataItems);
61
- }
62
- }
63
- else {
64
- bitIntDataItems = bitIntDataItems.slice(0, outputLength);
65
- }
66
- bitIntDataItems = bitIntDataItems.reverse();
67
- return bitIntDataItems;
68
- }
69
- /*
70
- Identity function for message
71
-
72
- Can be used to truncate the message before hashing it
73
- as part of the public parameters.
74
- */
75
- static prehash_message(M) {
76
- return M;
77
- }
78
- /*
79
- Hash the key and message to create `r`, the blinding factor for this signature.
80
-
81
- If the same `r` value is used more than once, the key for the signature is revealed.
82
-
83
- From: https://eprint.iacr.org/2015/677.pdf (EdDSA for more curves)
84
-
85
- Page 3:
86
-
87
- (Implementation detail: To save time in the computation of `rB`, the signer
88
- can replace `r` with `r mod L` before computing `rB`.)
89
- */
90
- static hash_secret_python(k, arg) {
91
- const byteArray0 = this.to_bytes(k.n);
92
- const byteArray1 = this.to_bytes(arg);
93
- const sum = byteArray0.concat(byteArray1);
94
- const digest1 = sha512.array(new Uint8Array(sum).buffer);
95
- let sha512StrItems;
96
- for (let i = 0; i < digest1.length; i++) {
97
- const itemInt = digest1[i];
98
- let st = itemInt.toString(16);
99
- if (st.length == 1) {
100
- st = "0" + st;
101
- }
102
- sha512StrItems = [st].concat(sha512StrItems);
103
- }
104
- const sha512MessageHexStr = sha512StrItems.join("");
105
- const sha512MessageHexStrBigInt = BigNumber.from("0x" + sha512MessageHexStr);
106
- const hashed = sha512MessageHexStrBigInt.mod(jubjub.JUBJUB_L);
107
- return hashed;
108
- }
109
- static B() {
110
- return Point.generate();
111
- }
112
- static sign(msg, key, B) {
113
- const copyKey = new FQ(key.n, key.m);
114
- const A = B.mul(copyKey.n);
115
- const M = this.prehash_message(msg);
116
- const r = this.hash_secret_python(key, M);
117
- const copy_r = BigNumber.from(r.toString());
118
- const R = B.mul(copy_r);
119
- const t = this.hash_public(R, A, M);
120
- const t_c = t;
121
- const key_n_t = key.n.mul(t_c);
122
- const left = r.add(key_n_t);
123
- const S = left.mod(jubjub.JUBJUB_E);
124
- const signatureResult = new Signature(R, new FQ(S));
125
- const signedMessage = new SignedMessage(A, signatureResult, msg);
126
- return signedMessage;
127
- }
128
- static as_scalar(point) {
129
- return [point.x.n, point.y.n];
130
- }
131
- static hash_public(R, A, M) {
132
- let inputMsg;
133
- inputMsg = this.as_scalar(R).concat(this.as_scalar(A)).concat([M]);
134
- const params = new PoseidonParams(field.SNARK_SCALAR_FIELD, 6, 6, 52, "poseidon", BigNumber.from(5), null, null, 128);
135
- const result = permunation.poseidon(inputMsg, params);
136
- return result;
137
- }
138
- }
139
- export function bnToBuf(bn) {
140
- let hex = BigInt(bn).toString(16);
141
- if (hex.length % 2) {
142
- hex = "0" + hex;
143
- }
144
- const len = hex.length / 2;
145
- const u8 = new Uint8Array(len);
146
- let i = 0;
147
- let j = 0;
148
- while (i < len) {
149
- u8[i] = parseInt(hex.slice(j, j + 2), 16);
150
- i += 1;
151
- j += 2;
152
- }
153
- return Array.from(u8);
154
- }
155
- export function bnToBufWithFixedLength(bn, outputLength) {
156
- let hex = BigInt(bn).toString(16);
157
- if (hex.length % 2) {
158
- hex = "0" + hex;
159
- }
160
- const len = hex.length / 2;
161
- const u8 = new Uint8Array(len);
162
- let i = 0;
163
- let j = 0;
164
- while (i < len) {
165
- u8[i] = parseInt(hex.slice(j, j + 2), 16);
166
- i += 1;
167
- j += 2;
168
- }
169
- let bitIntDataItems = Array.from(u8);
170
- const more = outputLength - bitIntDataItems.length;
171
- if (more > 0) {
172
- for (let i = 0; i < more; i++) {
173
- bitIntDataItems = [0].concat(bitIntDataItems);
174
- }
175
- }
176
- else {
177
- bitIntDataItems = bitIntDataItems.slice(0, outputLength);
178
- }
179
- return bitIntDataItems;
180
- }
181
- export function bufToBn(buf) {
182
- let hex;
183
- hex = [];
184
- const u8 = Uint8Array.from(buf);
185
- u8.forEach(function (i) {
186
- let h = i.toString(16);
187
- if (h.length % 2) {
188
- h = "0" + h;
189
- }
190
- hex.push(h);
191
- });
192
- return BigInt("0x" + hex.join(""));
193
- }
194
- export function bytesToHexString(bytes) {
195
- let strItems;
196
- strItems = [];
197
- for (let i = 0; i < bytes.length; i++) {
198
- const item = bytes[i];
199
- let st = item.toString(16);
200
- if (st.length == 1) {
201
- st = "0" + st;
202
- }
203
- // st = st.toUpperCase()
204
- strItems.push(st);
205
- }
206
- const strItemsJoined = strItems.join("");
207
- return strItemsJoined;
208
- }
@@ -1,17 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- export declare class field {
3
- static SNARK_SCALAR_FIELD: BigNumber;
4
- static FR_ORDER: BigNumber;
5
- }
6
- export declare class FQ {
7
- m: BigNumber;
8
- n: BigNumber;
9
- constructor(n: BigNumber, field_modulus?: BigNumber);
10
- add(other: BigNumber): FQ;
11
- mul(other: BigNumber): FQ;
12
- sub(other: BigNumber): FQ;
13
- div(other: BigNumber): FQ;
14
- static one(modulus?: BigNumber): FQ;
15
- static zero(modulus?: BigNumber): FQ;
16
- }
17
- export declare function modulo(n: BigNumber, p: BigNumber, m: BigNumber): BigNumber;
@@ -1,61 +0,0 @@
1
- import { BigNumber } from "ethers";
2
- import { BigInteger } from "jsbn";
3
- export class field {
4
- }
5
- // Fq is the base field of Jubjub
6
- field.SNARK_SCALAR_FIELD = BigNumber.from("21888242871839275222246405745257275088548364400416034343698204186575808495617");
7
- // Fr is the scalar field of Jubjub
8
- field.FR_ORDER = BigNumber.from("21888242871839275222246405745257275088614511777268538073601725287587578984328");
9
- // A class for field elements in FQ. Wrap a number in this class,
10
- // and it becomes a field element.
11
- export class FQ {
12
- constructor(n, field_modulus = field.SNARK_SCALAR_FIELD) {
13
- this.m = field_modulus;
14
- this.n = n.mod(this.m);
15
- }
16
- //
17
- // Use this.n as other
18
- //
19
- add(other) {
20
- const on = other;
21
- const n = (this.n.add(on)).mod(this.m);
22
- return new FQ(n, this.m);
23
- }
24
- mul(other) {
25
- const on = other;
26
- const n = this.n.mul(on).mod(this.m);
27
- return new FQ(n, this.m);
28
- }
29
- sub(other) {
30
- const on = other;
31
- let new_n;
32
- if (this.n.gte(on)) {
33
- new_n = (this.n.sub(on)).mod(this.m);
34
- }
35
- else {
36
- new_n = (this.n.sub(on).add(this.m)).mod(this.m);
37
- }
38
- return new FQ(new_n, this.m);
39
- }
40
- div(other) {
41
- const on_c = other;
42
- const m_c = this.m;
43
- const two_c = BigNumber.from("2");
44
- const on_power_c = modulo(on_c, m_c.sub(two_c), m_c);
45
- const n_on_power_remainder = this.n.mul(on_power_c).mod(this.m);
46
- return new FQ(n_on_power_remainder, this.m);
47
- }
48
- static one(modulus = field.SNARK_SCALAR_FIELD) {
49
- return new FQ(BigNumber.from("1"), modulus);
50
- }
51
- static zero(modulus = field.SNARK_SCALAR_FIELD) {
52
- return new FQ(BigNumber.from("0"), modulus);
53
- }
54
- }
55
- export function modulo(n, p, m) {
56
- const n_ = new BigInteger(n.toString());
57
- const p_ = new BigInteger(p.toString());
58
- const m_ = new BigInteger(m.toString());
59
- const result = n_.modPow(p_, m_);
60
- return BigNumber.from(result.toString());
61
- }
@@ -1,137 +0,0 @@
1
- import * as ethUtil from 'ethereumjs-util';
2
- import BN from 'bn.js';
3
- import BigNumber from 'bignumber.js';
4
- import { Buffer } from 'buffer';
5
- import { AmmPoolInfoV3, LoopringMap, MarketInfo, TokenInfo, TOKENMAPLIST, TokenRelatedInfo, DefiMarketInfo } from './defs';
6
- /**
7
- * Returns hex string with '0x' prefix
8
- * @param input
9
- * @returns {string}
10
- */
11
- export declare function addHexPrefix(input: any): string;
12
- /**
13
- *
14
- * @param mixed Buffer|number|string (hex string must be with '0x' prefix)
15
- * @returns {Buffer}
16
- */
17
- export declare function toBuffer(mixed: any): Buffer;
18
- /**
19
- *
20
- * @param num number|string (hex string must be with '0x' prefix)
21
- * @param places number of zeros to pad
22
- * @returns {Buffer}
23
- */
24
- export declare function zeroPad(num: any, places: any): Buffer<ArrayBufferLike>;
25
- /**
26
- *
27
- * @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
28
- * @returns {string}
29
- */
30
- export declare function toHex(mixed: number | BigNumber | BN | Buffer | string | Uint8Array | BigInt): string;
31
- /**
32
- *
33
- * @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
34
- * @returns {number}
35
- */
36
- export declare function toNumber(mixed: number | BigNumber | BN | Buffer | string | Uint8Array): number;
37
- /**
38
- *
39
- * @param mixed number | BigNumber | BN | Buffer | string | Uint8Array
40
- * @returns {BigNumber}
41
- */
42
- export declare function toBig(mixed: number | BigNumber | BN | Buffer | string | Uint8Array): BigNumber;
43
- /**
44
- *
45
- * @param mixed number | BigNumber | BN | Buffer | string
46
- * @returns {BN}
47
- */
48
- export declare function toBN(mixed: any): ethUtil.BN;
49
- /**
50
- *
51
- * @param value number | BigNumber | Buffer | string
52
- * @returns {BN}
53
- */
54
- export declare function fromGWEI(value: any): BigNumber;
55
- /**
56
- *
57
- * @param value number | BigNumber | Buffer | string
58
- * @returns {BN}
59
- */
60
- export declare function toGWEI(value: any): BigNumber;
61
- /**
62
- * Returns formatted hex string of a given private key
63
- * @param mixed Buffer | string | Uint8Array
64
- * @returns {string}
65
- */
66
- export declare function formatKey(mixed: Buffer | string | Uint8Array): string;
67
- /**
68
- * Returns hex string of a given address
69
- * @param mixed Buffer | string |Uint8Array
70
- * @returns {string}
71
- */
72
- export declare function formatAddress(mixed: Buffer | string | Uint8Array): string;
73
- /**
74
- * Returns hex string without '0x' prefix
75
- * @param input string
76
- * @returns {string}
77
- */
78
- export declare function clearHexPrefix(input: any): string;
79
- /**
80
- *
81
- * @param hex
82
- * @returns {string}
83
- */
84
- export declare function padLeftEven(hex: any): any;
85
- /**
86
- * Returns symbol of a given kind of currency
87
- * @param settingsCurrency
88
- * @returns {*}
89
- */
90
- export declare function getDisplaySymbol(settingsCurrency: any): "" | "¥" | "$";
91
- /**
92
- * Returns number in string with a given precision
93
- * @param number number | BigNumber
94
- * @param precision number
95
- * @param ceil bool round up
96
- * @returns {string}
97
- */
98
- export declare function toFixed(number: any, precision: any, ceil: any): string;
99
- export declare function formatEddsaKey(key: any): string;
100
- /**
101
- * Returns a number with commas as thousands separators
102
- * @param number number
103
- * @returns {*}
104
- */
105
- export declare function numberWithCommas(number: any): any;
106
- export declare function sortObjDictionary(obj: {
107
- [key: string]: any;
108
- }): Map<string, any>;
109
- export declare function makeMarket<R extends TokenInfo = TokenInfo>(raw_data: R[]): TOKENMAPLIST;
110
- export declare function makeAmmPool<R>(raw_data: any): {
111
- ammpools: LoopringMap<AmmPoolInfoV3>;
112
- pairs: LoopringMap<TokenRelatedInfo>;
113
- };
114
- export declare function makeMarkets<R, C extends MarketInfo>(raw_data: any, url?: string): {
115
- markets: LoopringMap<C>;
116
- pairs: LoopringMap<TokenRelatedInfo>;
117
- tokenArr: string[];
118
- tokenArrStr: string;
119
- marketArr: string[];
120
- marketArrStr: string;
121
- };
122
- export declare function makeMarketsWithIdIndex<C extends MarketInfo>(raw_data: any, url: string | undefined, idIndex: any): {
123
- markets: LoopringMap<C>;
124
- pairs: LoopringMap<TokenRelatedInfo>;
125
- tokenArr: string[];
126
- tokenArrStr: string;
127
- marketArr: string[];
128
- marketArrStr: string;
129
- };
130
- export declare function makeInvestMarkets<C extends DefiMarketInfo>(raw_data: any, types?: string[]): {
131
- markets: LoopringMap<C>;
132
- pairs: LoopringMap<TokenRelatedInfo>;
133
- tokenArr: string[];
134
- tokenArrStr: string;
135
- marketArr: string[];
136
- marketArrStr: string;
137
- };