@web3auth/no-modal 10.15.0 → 11.0.0-beta.0

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 (321) hide show
  1. package/dist/lib.cjs/base/connector/baseConnector.js +104 -2
  2. package/dist/lib.cjs/base/connector/connectorStatus.js +2 -0
  3. package/dist/lib.cjs/base/connector/constants.js +4 -2
  4. package/dist/lib.cjs/base/connector/utils.js +0 -21
  5. package/dist/lib.cjs/base/constants.js +4 -0
  6. package/dist/lib.cjs/base/cookie.js +6 -20
  7. package/dist/lib.cjs/base/errors/index.js +36 -12
  8. package/dist/lib.cjs/base/utils.js +10 -11
  9. package/dist/lib.cjs/base/wallet/index.js +7 -0
  10. package/dist/lib.cjs/base/wallet/solana.js +83 -0
  11. package/dist/lib.cjs/connectors/auth-connector/authConnector.js +145 -49
  12. package/dist/lib.cjs/connectors/auth-connector/authSolanaWallet.js +187 -0
  13. package/dist/lib.cjs/connectors/base-evm-connector/baseEvmConnector.js +18 -40
  14. package/dist/lib.cjs/connectors/base-solana-connector/baseSolanaConnector.js +30 -56
  15. package/dist/lib.cjs/connectors/coinbase-connector/coinbaseConnector.js +19 -14
  16. package/dist/lib.cjs/connectors/injected-evm-connector/injectedEvmConnector.js +18 -13
  17. package/dist/lib.cjs/connectors/injected-solana-connector/walletStandardConnector.js +24 -36
  18. package/dist/lib.cjs/connectors/metamask-connector/metamaskConnector.js +321 -133
  19. package/dist/lib.cjs/connectors/utils.js +8 -2
  20. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +12 -38
  21. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/config.js +4 -3
  22. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +73 -63
  23. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +24 -51
  24. package/dist/lib.cjs/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +144 -0
  25. package/dist/lib.cjs/index.js +36 -71
  26. package/dist/lib.cjs/noModal.js +223 -133
  27. package/dist/lib.cjs/plugins/wallet-services-plugin/plugin.js +23 -39
  28. package/dist/lib.cjs/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +12 -10
  29. package/dist/lib.cjs/providers/account-abstraction-provider/providers/utils.js +8 -6
  30. package/dist/lib.cjs/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +47 -44
  31. package/dist/lib.cjs/providers/base-provider/CommonJRPCProvider.js +1 -3
  32. package/dist/lib.cjs/providers/base-provider/baseProvider.js +4 -2
  33. package/dist/lib.cjs/providers/base-provider/commonPrivateKeyProvider.js +8 -11
  34. package/dist/lib.cjs/providers/base-provider/index.js +0 -1
  35. package/dist/lib.cjs/providers/base-provider/jrpcClient.js +18 -19
  36. package/dist/lib.cjs/providers/base-provider/utils.js +0 -3
  37. package/dist/lib.cjs/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +22 -43
  38. package/dist/lib.cjs/providers/ethereum-provider/rpc/jrpcClient.js +18 -19
  39. package/dist/lib.cjs/providers/ethereum-provider/rpc/walletMiddleware.js +200 -0
  40. package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +9 -18
  41. package/dist/lib.cjs/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +2 -1
  42. package/dist/lib.cjs/providers/xrpl-provider/rpc/JrpcClient.js +19 -26
  43. package/dist/lib.cjs/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +46 -37
  44. package/dist/lib.cjs/react/context/WalletServicesInnerContext.js +2 -69
  45. package/dist/lib.cjs/react/context/Web3AuthInnerContext.js +6 -161
  46. package/dist/lib.cjs/react/context/useWalletServicesContextValue.js +76 -0
  47. package/dist/lib.cjs/react/context/useWeb3AuthInnerContextValue.js +202 -0
  48. package/dist/lib.cjs/react/hooks/{useIdentityToken.js → useAuthTokenInfo.js} +6 -7
  49. package/dist/lib.cjs/react/hooks/useCheckout.js +4 -2
  50. package/dist/lib.cjs/react/hooks/useFunding.js +4 -2
  51. package/dist/lib.cjs/react/hooks/useReceive.js +4 -2
  52. package/dist/lib.cjs/react/hooks/useSwap.js +4 -2
  53. package/dist/lib.cjs/react/hooks/useWalletConnectScanner.js +4 -2
  54. package/dist/lib.cjs/react/hooks/useWalletServicesPlugin.js +3 -10
  55. package/dist/lib.cjs/react/hooks/useWalletUI.js +4 -2
  56. package/dist/lib.cjs/react/hooks/useWeb3Auth.js +1 -22
  57. package/dist/lib.cjs/react/hooks/useWeb3AuthInner.js +4 -2
  58. package/dist/lib.cjs/react/index.js +10 -2
  59. package/dist/lib.cjs/react/solana/hooks/useSignAndSendTransaction.js +22 -4
  60. package/dist/lib.cjs/react/solana/hooks/useSignMessage.js +20 -2
  61. package/dist/lib.cjs/react/solana/hooks/useSignTransaction.js +22 -3
  62. package/dist/lib.cjs/react/solana/hooks/useSolanaWallet.js +34 -51
  63. package/dist/lib.cjs/react/solana/index.js +2 -0
  64. package/dist/lib.cjs/react/solana/provider.js +167 -0
  65. package/dist/lib.cjs/react/wagmi/provider.js +10 -8
  66. package/dist/lib.cjs/types/base/connector/baseConnector.d.ts +21 -5
  67. package/dist/lib.cjs/types/base/connector/connectorStatus.d.ts +1 -0
  68. package/dist/lib.cjs/types/base/connector/constants.d.ts +3 -0
  69. package/dist/lib.cjs/types/base/connector/interfaces.d.ts +23 -12
  70. package/dist/lib.cjs/types/base/connector/utils.d.ts +0 -3
  71. package/dist/lib.cjs/types/base/constants.d.ts +1 -0
  72. package/dist/lib.cjs/types/base/cookie.d.ts +0 -7
  73. package/dist/lib.cjs/types/base/core/IWeb3Auth.d.ts +24 -12
  74. package/dist/lib.cjs/types/base/errors/index.d.ts +2 -3
  75. package/dist/lib.cjs/types/base/hooks/index.d.ts +2 -2
  76. package/dist/lib.cjs/types/base/interfaces.d.ts +5 -1
  77. package/dist/lib.cjs/types/base/utils.d.ts +2 -1
  78. package/dist/lib.cjs/types/base/wallet/index.d.ts +3 -0
  79. package/dist/lib.cjs/types/base/wallet/solana.d.ts +19 -0
  80. package/dist/lib.cjs/types/connectors/auth-connector/authConnector.d.ts +11 -6
  81. package/dist/lib.cjs/types/connectors/auth-connector/authSolanaWallet.d.ts +35 -0
  82. package/dist/lib.cjs/types/connectors/base-evm-connector/baseEvmConnector.d.ts +2 -2
  83. package/dist/lib.cjs/types/connectors/base-solana-connector/baseSolanaConnector.d.ts +2 -2
  84. package/dist/lib.cjs/types/connectors/injected-evm-connector/injectedEvmConnector.d.ts +2 -2
  85. package/dist/lib.cjs/types/connectors/injected-solana-connector/walletStandardConnector.d.ts +10 -7
  86. package/dist/lib.cjs/types/connectors/metamask-connector/metamaskConnector.d.ts +35 -3
  87. package/dist/lib.cjs/types/connectors/utils.d.ts +2 -0
  88. package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.d.ts +0 -1
  89. package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/walletConnectV2Utils.d.ts +1 -5
  90. package/dist/lib.cjs/types/connectors/wallet-connect-v2-connector/wcSolanaWallet.d.ts +26 -0
  91. package/dist/lib.cjs/types/noModal.d.ts +12 -8
  92. package/dist/lib.cjs/types/plugins/wallet-services-plugin/plugin.d.ts +1 -4
  93. package/dist/lib.cjs/types/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.d.ts +4 -4
  94. package/dist/lib.cjs/types/providers/base-provider/jrpcClient.d.ts +2 -5
  95. package/dist/lib.cjs/types/providers/base-provider/utils.d.ts +0 -1
  96. package/dist/lib.cjs/types/providers/ethereum-provider/index.d.ts +0 -1
  97. package/dist/lib.cjs/types/providers/ethereum-provider/rpc/ethRpcMiddlewares.d.ts +4 -4
  98. package/dist/lib.cjs/types/providers/ethereum-provider/rpc/index.d.ts +1 -1
  99. package/dist/lib.cjs/types/providers/ethereum-provider/rpc/jrpcClient.d.ts +2 -5
  100. package/dist/lib.cjs/types/providers/ethereum-provider/rpc/walletMiddleware.d.ts +3 -0
  101. package/dist/lib.cjs/types/providers/index.d.ts +0 -1
  102. package/dist/lib.cjs/types/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.d.ts +0 -1
  103. package/dist/lib.cjs/types/providers/xrpl-provider/rpc/JrpcClient.d.ts +3 -7
  104. package/dist/lib.cjs/types/providers/xrpl-provider/rpc/xrplRpcMiddlewares.d.ts +5 -12
  105. package/dist/lib.cjs/types/react/context/index.d.ts +4 -0
  106. package/dist/lib.cjs/types/react/context/useWalletServicesContextValue.d.ts +12 -0
  107. package/dist/lib.cjs/types/react/context/useWeb3AuthInnerContextValue.d.ts +26 -0
  108. package/dist/lib.cjs/types/react/hooks/index.d.ts +1 -1
  109. package/dist/lib.cjs/types/react/hooks/{useIdentityToken.d.ts → useAuthTokenInfo.d.ts} +4 -4
  110. package/dist/lib.cjs/types/react/hooks/useWeb3Auth.d.ts +1 -2
  111. package/dist/lib.cjs/types/react/hooks/useWeb3AuthConnect.d.ts +2 -2
  112. package/dist/lib.cjs/types/react/index.d.ts +1 -0
  113. package/dist/lib.cjs/types/react/solana/hooks/useSignAndSendTransaction.d.ts +7 -2
  114. package/dist/lib.cjs/types/react/solana/hooks/useSignTransaction.d.ts +8 -3
  115. package/dist/lib.cjs/types/react/solana/hooks/useSolanaWallet.d.ts +17 -4
  116. package/dist/lib.cjs/types/react/solana/index.d.ts +1 -0
  117. package/dist/lib.cjs/types/react/solana/provider.d.ts +26 -0
  118. package/dist/lib.cjs/types/vue/composables/index.d.ts +2 -1
  119. package/dist/lib.cjs/types/vue/composables/{useIdentityToken.d.ts → useAuthTokenInfo.d.ts} +3 -3
  120. package/dist/lib.cjs/types/vue/composables/useInjectedWeb3AuthInnerContext.d.ts +1 -0
  121. package/dist/lib.cjs/types/vue/composables/useWeb3Auth.d.ts +1 -2
  122. package/dist/lib.cjs/types/vue/composables/useWeb3AuthConnect.d.ts +2 -2
  123. package/dist/lib.cjs/types/vue/index.d.ts +2 -0
  124. package/dist/lib.cjs/types/vue/interfaces.d.ts +2 -2
  125. package/dist/lib.cjs/types/vue/solana/composables/index.d.ts +1 -0
  126. package/dist/lib.cjs/types/vue/solana/composables/useSignAndSendTransaction.d.ts +7 -2
  127. package/dist/lib.cjs/types/vue/solana/composables/useSignTransaction.d.ts +8 -3
  128. package/dist/lib.cjs/types/vue/solana/composables/useSolanaClient.d.ts +7 -0
  129. package/dist/lib.cjs/types/vue/solana/composables/useSolanaWallet.d.ts +17 -4
  130. package/dist/lib.cjs/types/vue/solana/constants.d.ts +3 -0
  131. package/dist/lib.cjs/types/vue/solana/index.d.ts +2 -0
  132. package/dist/lib.cjs/types/vue/solana/provider.d.ts +8 -0
  133. package/dist/lib.cjs/types/vue/useWalletServicesInnerContextValue.d.ts +13 -0
  134. package/dist/lib.cjs/types/vue/useWeb3AuthInnerContextValue.d.ts +26 -0
  135. package/dist/lib.cjs/types/x402/index.d.ts +43 -0
  136. package/dist/lib.cjs/types/x402/interfaces.d.ts +11 -0
  137. package/dist/lib.cjs/types/x402/react.d.ts +17 -0
  138. package/dist/lib.cjs/types/x402/vue.d.ts +18 -0
  139. package/dist/lib.cjs/vue/WalletServicesInnerProvider.js +9 -54
  140. package/dist/lib.cjs/vue/Web3AuthProvider.js +16 -177
  141. package/dist/lib.cjs/vue/composables/{useIdentityToken.js → useAuthTokenInfo.js} +10 -8
  142. package/dist/lib.cjs/vue/composables/useCheckout.js +4 -2
  143. package/dist/lib.cjs/vue/composables/useEnableMFA.js +4 -2
  144. package/dist/lib.cjs/vue/composables/useFunding.js +4 -2
  145. package/dist/lib.cjs/vue/composables/useInjectedWeb3AuthInnerContext.js +29 -0
  146. package/dist/lib.cjs/vue/composables/useManageMFA.js +4 -2
  147. package/dist/lib.cjs/vue/composables/useReceive.js +4 -2
  148. package/dist/lib.cjs/vue/composables/useSwap.js +4 -2
  149. package/dist/lib.cjs/vue/composables/useSwitchChain.js +4 -2
  150. package/dist/lib.cjs/vue/composables/useWalletConnectScanner.js +4 -2
  151. package/dist/lib.cjs/vue/composables/useWalletUI.js +4 -2
  152. package/dist/lib.cjs/vue/composables/useWeb3Auth.js +1 -26
  153. package/dist/lib.cjs/vue/composables/useWeb3AuthConnect.js +4 -2
  154. package/dist/lib.cjs/vue/composables/useWeb3AuthDisconnect.js +4 -2
  155. package/dist/lib.cjs/vue/composables/useWeb3AuthInner.js +2 -20
  156. package/dist/lib.cjs/vue/composables/useWeb3AuthUser.js +4 -2
  157. package/dist/lib.cjs/vue/index.js +8 -2
  158. package/dist/lib.cjs/vue/solana/composables/useSignAndSendTransaction.js +6 -3
  159. package/dist/lib.cjs/vue/solana/composables/useSignMessage.js +6 -3
  160. package/dist/lib.cjs/vue/solana/composables/useSignTransaction.js +6 -3
  161. package/dist/lib.cjs/vue/solana/composables/useSolanaClient.js +14 -0
  162. package/dist/lib.cjs/vue/solana/composables/useSolanaWallet.js +60 -41
  163. package/dist/lib.cjs/vue/solana/constants.js +5 -0
  164. package/dist/lib.cjs/vue/solana/index.js +6 -0
  165. package/dist/lib.cjs/vue/solana/provider.js +107 -0
  166. package/dist/lib.cjs/vue/useWalletServicesInnerContextValue.js +75 -0
  167. package/dist/lib.cjs/vue/useWeb3AuthInnerContextValue.js +217 -0
  168. package/dist/lib.cjs/vue/wagmi/provider.js +12 -8
  169. package/dist/lib.cjs/x402/index.js +175 -0
  170. package/dist/lib.cjs/x402/interfaces.js +5 -0
  171. package/dist/lib.cjs/x402/react.js +64 -0
  172. package/dist/lib.cjs/x402/vue.js +58 -0
  173. package/dist/lib.esm/base/connector/baseConnector.js +104 -2
  174. package/dist/lib.esm/base/connector/connectorStatus.js +2 -1
  175. package/dist/lib.esm/base/connector/constants.js +4 -2
  176. package/dist/lib.esm/base/connector/utils.js +1 -19
  177. package/dist/lib.esm/base/constants.js +4 -1
  178. package/dist/lib.esm/base/cookie.js +7 -20
  179. package/dist/lib.esm/base/errors/index.js +36 -12
  180. package/dist/lib.esm/base/utils.js +10 -7
  181. package/dist/lib.esm/base/wallet/index.js +2 -1
  182. package/dist/lib.esm/base/wallet/solana.js +81 -0
  183. package/dist/lib.esm/connectors/auth-connector/authConnector.js +143 -50
  184. package/dist/lib.esm/connectors/auth-connector/authSolanaWallet.js +175 -0
  185. package/dist/lib.esm/connectors/base-evm-connector/baseEvmConnector.js +17 -39
  186. package/dist/lib.esm/connectors/base-solana-connector/baseSolanaConnector.js +29 -55
  187. package/dist/lib.esm/connectors/coinbase-connector/coinbaseConnector.js +14 -11
  188. package/dist/lib.esm/connectors/injected-evm-connector/injectedEvmConnector.js +14 -11
  189. package/dist/lib.esm/connectors/injected-solana-connector/walletStandardConnector.js +19 -31
  190. package/dist/lib.esm/connectors/metamask-connector/metamaskConnector.js +335 -132
  191. package/dist/lib.esm/connectors/utils.js +9 -4
  192. package/dist/lib.esm/connectors/wallet-connect-v2-connector/WalletConnectV2Provider.js +11 -30
  193. package/dist/lib.esm/connectors/wallet-connect-v2-connector/config.js +1 -1
  194. package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Connector.js +70 -61
  195. package/dist/lib.esm/connectors/wallet-connect-v2-connector/walletConnectV2Utils.js +21 -49
  196. package/dist/lib.esm/connectors/wallet-connect-v2-connector/wcSolanaWallet.js +130 -0
  197. package/dist/lib.esm/index.js +9 -17
  198. package/dist/lib.esm/noModal.js +225 -133
  199. package/dist/lib.esm/plugins/wallet-services-plugin/plugin.js +18 -37
  200. package/dist/lib.esm/providers/account-abstraction-provider/providers/AccountAbstractionProvider.js +9 -9
  201. package/dist/lib.esm/providers/account-abstraction-provider/providers/utils.js +3 -3
  202. package/dist/lib.esm/providers/account-abstraction-provider/rpc/ethRpcMiddlewares.js +48 -45
  203. package/dist/lib.esm/providers/base-provider/CommonJRPCProvider.js +2 -4
  204. package/dist/lib.esm/providers/base-provider/commonPrivateKeyProvider.js +9 -12
  205. package/dist/lib.esm/providers/base-provider/index.js +1 -1
  206. package/dist/lib.esm/providers/base-provider/jrpcClient.js +20 -19
  207. package/dist/lib.esm/providers/base-provider/utils.js +1 -3
  208. package/dist/lib.esm/providers/ethereum-provider/rpc/ethRpcMiddlewares.js +23 -44
  209. package/dist/lib.esm/providers/ethereum-provider/rpc/jrpcClient.js +20 -19
  210. package/dist/lib.esm/providers/ethereum-provider/rpc/walletMiddleware.js +201 -0
  211. package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplPrivateKeyProvider.js +6 -17
  212. package/dist/lib.esm/providers/xrpl-provider/providers/privateKeyProviders/xrplWalletUtils.js +2 -1
  213. package/dist/lib.esm/providers/xrpl-provider/rpc/JrpcClient.js +21 -25
  214. package/dist/lib.esm/providers/xrpl-provider/rpc/xrplRpcMiddlewares.js +48 -38
  215. package/dist/lib.esm/react/context/WalletServicesInnerContext.js +3 -57
  216. package/dist/lib.esm/react/context/Web3AuthInnerContext.js +7 -152
  217. package/dist/lib.esm/react/context/useWalletServicesContextValue.js +59 -0
  218. package/dist/lib.esm/react/context/useWeb3AuthInnerContextValue.js +188 -0
  219. package/dist/lib.esm/react/hooks/{useIdentityToken.js → useAuthTokenInfo.js} +6 -7
  220. package/dist/lib.esm/react/hooks/useWalletServicesPlugin.js +3 -10
  221. package/dist/lib.esm/react/hooks/useWeb3Auth.js +1 -22
  222. package/dist/lib.esm/react/index.js +5 -1
  223. package/dist/lib.esm/react/solana/hooks/useSignAndSendTransaction.js +6 -4
  224. package/dist/lib.esm/react/solana/hooks/useSignMessage.js +4 -2
  225. package/dist/lib.esm/react/solana/hooks/useSignTransaction.js +6 -3
  226. package/dist/lib.esm/react/solana/hooks/useSolanaWallet.js +33 -28
  227. package/dist/lib.esm/react/solana/index.js +1 -0
  228. package/dist/lib.esm/react/solana/provider.js +150 -0
  229. package/dist/lib.esm/react/wagmi/provider.js +7 -7
  230. package/dist/lib.esm/vue/WalletServicesInnerProvider.js +4 -54
  231. package/dist/lib.esm/vue/Web3AuthProvider.js +7 -179
  232. package/dist/lib.esm/vue/composables/{useIdentityToken.js → useAuthTokenInfo.js} +6 -6
  233. package/dist/lib.esm/vue/composables/useInjectedWeb3AuthInnerContext.js +11 -0
  234. package/dist/lib.esm/vue/composables/useWeb3Auth.js +1 -26
  235. package/dist/lib.esm/vue/composables/useWeb3AuthInner.js +2 -6
  236. package/dist/lib.esm/vue/index.js +4 -1
  237. package/dist/lib.esm/vue/solana/composables/useSignAndSendTransaction.js +2 -1
  238. package/dist/lib.esm/vue/solana/composables/useSignMessage.js +2 -1
  239. package/dist/lib.esm/vue/solana/composables/useSignTransaction.js +3 -2
  240. package/dist/lib.esm/vue/solana/composables/useSolanaClient.js +12 -0
  241. package/dist/lib.esm/vue/solana/composables/useSolanaWallet.js +53 -35
  242. package/dist/lib.esm/vue/solana/constants.js +3 -0
  243. package/dist/lib.esm/vue/solana/index.js +3 -0
  244. package/dist/lib.esm/vue/solana/provider.js +95 -0
  245. package/dist/lib.esm/vue/useWalletServicesInnerContextValue.js +58 -0
  246. package/dist/lib.esm/vue/useWeb3AuthInnerContextValue.js +204 -0
  247. package/dist/lib.esm/vue/wagmi/provider.js +9 -7
  248. package/dist/lib.esm/x402/index.js +170 -0
  249. package/dist/lib.esm/x402/interfaces.js +3 -0
  250. package/dist/lib.esm/x402/react.js +59 -0
  251. package/dist/lib.esm/x402/vue.js +54 -0
  252. package/package.json +78 -53
  253. package/dist/lib.cjs/providers/ethereum-mpc-provider/index.js +0 -7
  254. package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +0 -224
  255. package/dist/lib.cjs/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +0 -177
  256. package/dist/lib.cjs/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +0 -21
  257. package/dist/lib.cjs/providers/ethereum-provider/providers/converter.js +0 -88
  258. package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +0 -27
  259. package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +0 -383
  260. package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +0 -8
  261. package/dist/lib.cjs/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +0 -93
  262. package/dist/lib.cjs/providers/ethereum-provider/providers/utils.js +0 -29
  263. package/dist/lib.cjs/providers/ethereum-provider/rpc/walletMidddleware.js +0 -251
  264. package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +0 -65
  265. package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +0 -45
  266. package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/utils.js +0 -16
  267. package/dist/lib.cjs/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +0 -103
  268. package/dist/lib.cjs/providers/solana-provider/rpc/JrpcClient.js +0 -47
  269. package/dist/lib.cjs/providers/solana-provider/rpc/solanaRpcMiddlewares.js +0 -97
  270. package/dist/lib.cjs/providers/solana-provider/solanaWallet.js +0 -91
  271. package/dist/lib.cjs/types/connectors/injected-solana-connector/utils.d.ts +0 -3
  272. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/index.d.ts +0 -1
  273. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/index.d.ts +0 -1
  274. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.d.ts +0 -74
  275. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/index.d.ts +0 -1
  276. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.d.ts +0 -12
  277. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.d.ts +0 -3
  278. package/dist/lib.cjs/types/providers/ethereum-mpc-provider/rpc/interfaces.d.ts +0 -15
  279. package/dist/lib.cjs/types/providers/ethereum-provider/providers/converter.d.ts +0 -14
  280. package/dist/lib.cjs/types/providers/ethereum-provider/providers/index.d.ts +0 -1
  281. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.d.ts +0 -16
  282. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.d.ts +0 -28
  283. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/index.d.ts +0 -4
  284. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.d.ts +0 -46
  285. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.d.ts +0 -11
  286. package/dist/lib.cjs/types/providers/ethereum-provider/providers/privateKeyProviders/index.d.ts +0 -1
  287. package/dist/lib.cjs/types/providers/ethereum-provider/providers/utils.d.ts +0 -5
  288. package/dist/lib.cjs/types/providers/ethereum-provider/rpc/walletMidddleware.d.ts +0 -3
  289. package/dist/lib.cjs/types/providers/solana-provider/index.d.ts +0 -4
  290. package/dist/lib.cjs/types/providers/solana-provider/interface.d.ts +0 -22
  291. package/dist/lib.cjs/types/providers/solana-provider/providers/index.d.ts +0 -1
  292. package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.d.ts +0 -16
  293. package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/base/providerHandlers.d.ts +0 -3
  294. package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/index.d.ts +0 -2
  295. package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/utils.d.ts +0 -3
  296. package/dist/lib.cjs/types/providers/solana-provider/providers/injectedProviders/walletStandardProvider.d.ts +0 -9
  297. package/dist/lib.cjs/types/providers/solana-provider/rpc/JrpcClient.d.ts +0 -9
  298. package/dist/lib.cjs/types/providers/solana-provider/rpc/index.d.ts +0 -3
  299. package/dist/lib.cjs/types/providers/solana-provider/rpc/interfaces.d.ts +0 -27
  300. package/dist/lib.cjs/types/providers/solana-provider/rpc/solanaRpcMiddlewares.d.ts +0 -20
  301. package/dist/lib.cjs/types/providers/solana-provider/solanaWallet.d.ts +0 -29
  302. package/dist/lib.esm/providers/ethereum-mpc-provider/index.js +0 -1
  303. package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/EthereumSigningProvider.js +0 -206
  304. package/dist/lib.esm/providers/ethereum-mpc-provider/providers/signingProviders/signingUtils.js +0 -163
  305. package/dist/lib.esm/providers/ethereum-mpc-provider/rpc/ethRpcMiddlewares.js +0 -20
  306. package/dist/lib.esm/providers/ethereum-provider/providers/converter.js +0 -85
  307. package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/constants.js +0 -21
  308. package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/formatter.js +0 -378
  309. package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/interfaces.js +0 -8
  310. package/dist/lib.esm/providers/ethereum-provider/providers/privateKeyProviders/TransactionFormatter/utils.js +0 -88
  311. package/dist/lib.esm/providers/ethereum-provider/providers/utils.js +0 -24
  312. package/dist/lib.esm/providers/ethereum-provider/rpc/walletMidddleware.js +0 -258
  313. package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/baseInjectedProvider.js +0 -47
  314. package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/base/providerHandlers.js +0 -43
  315. package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/utils.js +0 -14
  316. package/dist/lib.esm/providers/solana-provider/providers/injectedProviders/walletStandardProvider.js +0 -91
  317. package/dist/lib.esm/providers/solana-provider/rpc/JrpcClient.js +0 -42
  318. package/dist/lib.esm/providers/solana-provider/rpc/solanaRpcMiddlewares.js +0 -89
  319. package/dist/lib.esm/providers/solana-provider/solanaWallet.js +0 -92
  320. package/dist/noModal.umd.min.js +0 -2
  321. package/dist/noModal.umd.min.js.LICENSE.txt +0 -48
@@ -1,383 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
- var util = require('@ethereumjs/util');
6
- var bignumber_js = require('bignumber.js');
7
- require('@segment/analytics-next');
8
- var loglevel = require('../../../../../base/loglevel.js');
9
- require('@toruslabs/base-controllers');
10
- require('@web3auth/auth');
11
- require('../../../../../base/errors/index.js');
12
- require('../../../../../base/wallet/index.js');
13
- require('../../../../../base/connector/connectorStatus.js');
14
- require('../../../../../base/connector/constants.js');
15
- require('jwt-decode');
16
- require('../../../../../base/plugin/errors.js');
17
- require('../../../../../base/plugin/IPlugin.js');
18
- require('@toruslabs/constants');
19
- require('@toruslabs/http-helpers');
20
- var converter = require('../../converter.js');
21
- var utils = require('../../utils.js');
22
- var constants = require('./constants.js');
23
- var utils$1 = require('./utils.js');
24
-
25
- class TransactionFormatter {
26
- constructor({
27
- getProviderEngineProxy
28
- }) {
29
- // https://0x.org/docs/introduction/0x-cheat-sheet#swap-api-endpoints
30
- _defineProperty(this, "API_SUPPORTED_CHAINIDS", new Set(["0x1", "0x5", "0x13881", "0xa4b1", "0xa86a", "0x2105", "0x38", "0xfa", "0xa", "0x89"]));
31
- _defineProperty(this, "chainConfig", null);
32
- _defineProperty(this, "getProviderEngineProxy", void 0);
33
- _defineProperty(this, "isEIP1559Compatible", false);
34
- this.getProviderEngineProxy = getProviderEngineProxy;
35
- }
36
- get providerProxy() {
37
- return this.getProviderEngineProxy();
38
- }
39
- async init() {
40
- this.chainConfig = await this.providerProxy.request({
41
- method: "eth_provider_config"
42
- });
43
- this.isEIP1559Compatible = await this.getEIP1559Compatibility();
44
- }
45
- async formatTransaction(txParams) {
46
- if (!this.chainConfig) throw new Error("Chain config not initialized");
47
- const clonedTxParams = _objectSpread({}, txParams);
48
- if (clonedTxParams.nonce === undefined) clonedTxParams.nonce = await this.providerProxy.request({
49
- method: "eth_getTransactionCount",
50
- params: [txParams.from, "latest"]
51
- });
52
- if (!this.isEIP1559Compatible && clonedTxParams.gasPrice) {
53
- if (clonedTxParams.maxFeePerGas) delete clonedTxParams.maxFeePerGas;
54
- if (clonedTxParams.maxPriorityFeePerGas) delete clonedTxParams.maxPriorityFeePerGas;
55
- // if user provides gas Limit, we should use it instead
56
- // if gas is not provided explicitly, estimate it.
57
- if (!clonedTxParams.gasLimit) {
58
- if (!clonedTxParams.gas) {
59
- const defaultGasLimit = await this.getDefaultGasLimit(clonedTxParams);
60
- if (defaultGasLimit) {
61
- clonedTxParams.gasLimit = defaultGasLimit;
62
- }
63
- } else {
64
- clonedTxParams.gasLimit = util.addHexPrefix(clonedTxParams.gas);
65
- }
66
- }
67
- return clonedTxParams;
68
- }
69
- if (!clonedTxParams.gasLimit) {
70
- if (!clonedTxParams.gas) {
71
- const defaultGasLimit = await this.getDefaultGasLimit(clonedTxParams);
72
- if (defaultGasLimit) {
73
- clonedTxParams.gasLimit = defaultGasLimit;
74
- }
75
- } else {
76
- clonedTxParams.gasLimit = util.addHexPrefix(clonedTxParams.gas);
77
- }
78
- }
79
- const {
80
- gasPrice: defaultGasPrice,
81
- maxFeePerGas: defaultMaxFeePerGas,
82
- maxPriorityFeePerGas: defaultMaxPriorityFeePerGas
83
- } = await this.getDefaultGasFees(clonedTxParams);
84
- if (this.isEIP1559Compatible) {
85
- // If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas
86
- // then we set maxFeePerGas and maxPriorityFeePerGas to the suggested gasPrice.
87
- if (clonedTxParams.gasPrice && !clonedTxParams.maxFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
88
- clonedTxParams.maxFeePerGas = clonedTxParams.gasPrice;
89
- clonedTxParams.maxPriorityFeePerGas = utils.bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? util.stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof clonedTxParams.gasPrice === "string" ? util.stripHexPrefix(clonedTxParams.gasPrice) : clonedTxParams.gasPrice.toString()) ? util.addHexPrefix(defaultMaxPriorityFeePerGas) : util.addHexPrefix(clonedTxParams.gasPrice.toString());
90
- } else {
91
- if (defaultMaxFeePerGas && !clonedTxParams.maxFeePerGas) {
92
- // If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
93
- // with the one returned by the gasFeeController, if that is available.
94
- clonedTxParams.maxFeePerGas = util.addHexPrefix(defaultMaxFeePerGas);
95
- }
96
- if (defaultMaxPriorityFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
97
- // If the dapp has not set the gasPrice or the maxPriorityFeePerGas, then we set maxPriorityFeePerGas
98
- // with the one returned by the gasFeeController, if that is available.
99
- clonedTxParams.maxPriorityFeePerGas = util.addHexPrefix(defaultMaxPriorityFeePerGas);
100
- }
101
- if (defaultGasPrice && !clonedTxParams.maxFeePerGas) {
102
- // If the dapp has not set the gasPrice or the maxFeePerGas, and no maxFeePerGas is available
103
- // then we set maxFeePerGas to the defaultGasPrice, assuming it is
104
- // available.
105
- clonedTxParams.maxFeePerGas = util.addHexPrefix(defaultGasPrice);
106
- }
107
- if (clonedTxParams.maxFeePerGas && !clonedTxParams.maxPriorityFeePerGas) {
108
- // If the dapp has not set the gasPrice or the maxPriorityFeePerGas, and no maxPriorityFeePerGas is
109
- // available then we set maxPriorityFeePerGas to
110
- // clonedTxParams.maxFeePerGas, which will either be the gasPrice from the controller, the maxFeePerGas
111
- // set by the dapp, or the maxFeePerGas from the controller.
112
- clonedTxParams.maxPriorityFeePerGas = clonedTxParams.maxFeePerGas;
113
- }
114
- }
115
- // We remove the gasPrice param entirely when on an eip1559 compatible network
116
- delete clonedTxParams.gasPrice;
117
- } else {
118
- // We ensure that maxFeePerGas and maxPriorityFeePerGas are not in the transaction params
119
- // when not on a EIP1559 compatible network
120
- delete clonedTxParams.maxPriorityFeePerGas;
121
- delete clonedTxParams.maxFeePerGas;
122
- }
123
- // If we have gotten to this point, and none of gasPrice, maxPriorityFeePerGas or maxFeePerGas are
124
- // set on txParams, it means that either we are on a non-EIP1559 network and the dapp didn't suggest
125
- // a gas price, or we are on an EIP1559 network, and none of gasPrice, maxPriorityFeePerGas or maxFeePerGas
126
- // were available from either the dapp or the network.
127
- if (defaultGasPrice && !clonedTxParams.gasPrice && !clonedTxParams.maxPriorityFeePerGas && !clonedTxParams.maxFeePerGas) {
128
- clonedTxParams.gasPrice = defaultGasPrice;
129
- }
130
- clonedTxParams.type = Number.parseInt(this.isEIP1559Compatible ? constants.TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : constants.TRANSACTION_ENVELOPE_TYPES.LEGACY, 16);
131
- clonedTxParams.chainId = this.chainConfig.chainId;
132
- return clonedTxParams;
133
- }
134
- async fetchEthGasPriceEstimate() {
135
- const gasPrice = await this.providerProxy.request({
136
- method: "eth_gasPrice",
137
- params: []
138
- });
139
- return {
140
- gasPrice: converter.hexWEIToDecGWEI(gasPrice).toString()
141
- };
142
- }
143
- async fetchGasEstimatesViaEthFeeHistory() {
144
- const noOfBlocks = 10;
145
- const newestBlock = "latest";
146
- // get the 10, 50 and 95th percentile of the tip fees from the last 10 blocks
147
- const percentileValues = [10, 50, 95];
148
- const feeHistory = await this.providerProxy.request({
149
- method: "eth_feeHistory",
150
- params: [noOfBlocks, newestBlock, percentileValues]
151
- });
152
- // this is in hex wei
153
- const finalBaseFeePerGas = feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1];
154
- // this is in hex wei
155
- const priorityFeeCalcs = feeHistory.reward.reduce((acc, curr) => {
156
- return {
157
- slow: acc.slow.plus(new bignumber_js.BigNumber(curr[0], 16)),
158
- average: acc.average.plus(new bignumber_js.BigNumber(curr[1], 16)),
159
- fast: acc.fast.plus(new bignumber_js.BigNumber(curr[2], 16))
160
- };
161
- }, {
162
- slow: new bignumber_js.BigNumber(0),
163
- average: new bignumber_js.BigNumber(0),
164
- fast: new bignumber_js.BigNumber(0)
165
- });
166
- return {
167
- estimatedBaseFee: converter.hexWEIToDecGWEI(finalBaseFeePerGas).toString(),
168
- high: {
169
- maxWaitTimeEstimate: 30000,
170
- minWaitTimeEstimate: 15000,
171
- suggestedMaxFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.fast.plus(finalBaseFeePerGas).toString(16)).toString(),
172
- suggestedMaxPriorityFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.fast.toString(16)).toString()
173
- },
174
- medium: {
175
- maxWaitTimeEstimate: 45000,
176
- minWaitTimeEstimate: 15000,
177
- suggestedMaxFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.average.plus(finalBaseFeePerGas).toString(16)).toString(),
178
- suggestedMaxPriorityFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.average.toString(16)).toString()
179
- },
180
- low: {
181
- maxWaitTimeEstimate: 60000,
182
- minWaitTimeEstimate: 15000,
183
- suggestedMaxFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.slow.plus(finalBaseFeePerGas).toString(16)).toString(),
184
- suggestedMaxPriorityFeePerGas: converter.hexWEIToDecGWEI(priorityFeeCalcs.slow.toString(16)).toString()
185
- }
186
- };
187
- }
188
- async getEIP1559Compatibility() {
189
- const latestBlock = await this.providerProxy.request({
190
- method: "eth_getBlockByNumber",
191
- params: ["latest", false]
192
- });
193
- const supportsEIP1559 = latestBlock && latestBlock.baseFeePerGas !== undefined;
194
- return !!supportsEIP1559;
195
- }
196
- async fetchGasFeeEstimateData() {
197
- if (!this.chainConfig) throw new Error("Chain config not initialized");
198
- const isLegacyGasAPICompatible = this.chainConfig.chainId === "0x1";
199
- const chainId = Number.parseInt(this.chainConfig.chainId, 16);
200
- let gasData;
201
- try {
202
- if (this.isEIP1559Compatible) {
203
- let estimates;
204
- try {
205
- if (this.API_SUPPORTED_CHAINIDS.has(this.chainConfig.chainId)) {
206
- estimates = await utils$1.fetchEip1159GasEstimates(constants.EIP1559APIEndpoint.replace("<chain_id>", `${chainId}`));
207
- } else {
208
- throw new Error("Chain id not supported by api");
209
- }
210
- } catch {
211
- estimates = await this.fetchGasEstimatesViaEthFeeHistory();
212
- }
213
- gasData = {
214
- gasFeeEstimates: estimates,
215
- gasEstimateType: constants.GAS_ESTIMATE_TYPES.FEE_MARKET
216
- };
217
- } else if (isLegacyGasAPICompatible) {
218
- const estimates = await utils$1.fetchLegacyGasPriceEstimates(constants.LegacyGasAPIEndpoint.replace("<chain_id>", `${chainId}`));
219
- gasData = {
220
- gasFeeEstimates: estimates,
221
- gasEstimateType: constants.GAS_ESTIMATE_TYPES.LEGACY
222
- };
223
- } else {
224
- throw new Error("Main gas fee/price estimation failed. Use fallback");
225
- }
226
- } catch {
227
- try {
228
- const estimates = await this.fetchEthGasPriceEstimate();
229
- gasData = {
230
- gasFeeEstimates: estimates,
231
- gasEstimateType: constants.GAS_ESTIMATE_TYPES.ETH_GASPRICE
232
- };
233
- } catch (error) {
234
- throw new Error(`Gas fee/price estimation failed. Message: ${error.message}`);
235
- }
236
- }
237
- return gasData;
238
- }
239
- async getDefaultGasFees(txParams) {
240
- if (!this.isEIP1559Compatible && txParams.gasPrice || this.isEIP1559Compatible && txParams.maxFeePerGas && txParams.maxPriorityFeePerGas) {
241
- return {};
242
- }
243
- try {
244
- const {
245
- gasFeeEstimates,
246
- gasEstimateType
247
- } = await this.fetchGasFeeEstimateData();
248
- if (this.isEIP1559Compatible && gasEstimateType === constants.GAS_ESTIMATE_TYPES.FEE_MARKET) {
249
- const {
250
- medium: {
251
- suggestedMaxPriorityFeePerGas,
252
- suggestedMaxFeePerGas
253
- } = {}
254
- } = gasFeeEstimates;
255
- if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
256
- return {
257
- maxFeePerGas: util.addHexPrefix(converter.decGWEIToHexWEI(suggestedMaxFeePerGas)),
258
- maxPriorityFeePerGas: util.addHexPrefix(converter.decGWEIToHexWEI(suggestedMaxPriorityFeePerGas))
259
- };
260
- }
261
- } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.LEGACY) {
262
- // The LEGACY type includes low, medium and high estimates of
263
- // gas price values.
264
- return {
265
- gasPrice: util.addHexPrefix(converter.decGWEIToHexWEI(gasFeeEstimates.medium))
266
- };
267
- } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
268
- // The ETH_GASPRICE type just includes a single gas price property,
269
- // which we can assume was retrieved from eth_gasPrice
270
- return {
271
- gasPrice: util.addHexPrefix(converter.decGWEIToHexWEI(gasFeeEstimates.gasPrice))
272
- };
273
- }
274
- } catch (error) {
275
- loglevel.log.error(error);
276
- }
277
- const {
278
- gasPrice
279
- } = await this.fetchEthGasPriceEstimate();
280
- return {
281
- gasPrice: util.addHexPrefix(converter.decGWEIToHexWEI(gasPrice))
282
- };
283
- }
284
- async estimateTxGas(txMeta) {
285
- const txParams = _objectSpread({}, txMeta);
286
- // `eth_estimateGas` can fail if the user has insufficient balance for the
287
- // value being sent, or for the gas cost. We don't want to check their
288
- // balance here, we just want the gas estimate. The gas price is removed
289
- // to skip those balance checks. We check balance elsewhere. We also delete
290
- // maxFeePerGas and maxPriorityFeePerGas to support EIP-1559 txs.
291
- delete txParams.gasPrice;
292
- delete txParams.maxFeePerGas;
293
- delete txParams.maxPriorityFeePerGas;
294
- const gas = await this.providerProxy.request({
295
- method: "eth_estimateGas",
296
- params: [txParams]
297
- });
298
- return gas;
299
- }
300
- async analyzeGasUsage(txMeta) {
301
- const block = await this.providerProxy.request({
302
- method: "eth_getBlockByNumber",
303
- params: ["latest", false]
304
- });
305
- // fallback to block gasLimit
306
- const blockGasLimitBN = utils.hexToBn(block.gasLimit);
307
- const saferGasLimitBN = utils.BnMultiplyByFraction(blockGasLimitBN, 19, 20);
308
- let estimatedGasHex = utils.bnToHex(saferGasLimitBN);
309
- try {
310
- estimatedGasHex = await this.estimateTxGas(txMeta);
311
- } catch (error) {
312
- loglevel.log.warn(error);
313
- }
314
- return {
315
- blockGasLimit: block.gasLimit,
316
- estimatedGasHex
317
- };
318
- }
319
- addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
320
- const initialGasLimitBn = utils.hexToBn(initialGasLimitHex);
321
- const blockGasLimitBn = utils.hexToBn(blockGasLimitHex);
322
- const upperGasLimitBn = blockGasLimitBn.muln(0.9);
323
- const bufferedGasLimitBn = initialGasLimitBn.muln(multiplier);
324
- // if initialGasLimit is above blockGasLimit, dont modify it
325
- if (initialGasLimitBn.gt(upperGasLimitBn)) return utils.bnToHex(initialGasLimitBn);
326
- // if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
327
- if (bufferedGasLimitBn.lt(upperGasLimitBn)) return utils.bnToHex(bufferedGasLimitBn);
328
- // otherwise use blockGasLimit
329
- return utils.bnToHex(upperGasLimitBn);
330
- }
331
- async determineTransactionCategory(txParameters) {
332
- const {
333
- data,
334
- to
335
- } = txParameters;
336
- let code = "";
337
- let txCategory;
338
- if (data && !to) {
339
- txCategory = constants.TRANSACTION_TYPES.DEPLOY_CONTRACT;
340
- } else {
341
- try {
342
- code = await this.providerProxy.request({
343
- method: "eth_getCode",
344
- params: [to, "latest"]
345
- });
346
- } catch (error) {
347
- loglevel.log.warn(error);
348
- }
349
- const codeIsEmpty = !code || code === "0x" || code === "0x0";
350
- txCategory = codeIsEmpty ? constants.TRANSACTION_TYPES.SENT_ETHER : constants.TRANSACTION_TYPES.CONTRACT_INTERACTION;
351
- }
352
- return {
353
- transactionCategory: txCategory,
354
- code
355
- };
356
- }
357
- async getDefaultGasLimit(txParams) {
358
- const {
359
- transactionCategory
360
- } = await this.determineTransactionCategory(_objectSpread({}, txParams));
361
- if (txParams.gas) {
362
- return util.addHexPrefix(txParams.gas);
363
- }
364
- if (txParams.to && transactionCategory === constants.TRANSACTION_TYPES.SENT_ETHER) {
365
- // if there's data in the params, but there's no contract code, it's not a valid transaction
366
- if (txParams.data) {
367
- throw Error("TxGasUtil - Trying to call a function on a non-contract address");
368
- }
369
- const TWENTY_ONE_THOUSAND = 21000;
370
- // This is a standard ether simple send, gas requirement is exactly 21k
371
- return util.addHexPrefix(TWENTY_ONE_THOUSAND.toString(16));
372
- }
373
- const {
374
- blockGasLimit,
375
- estimatedGasHex
376
- } = await this.analyzeGasUsage(txParams);
377
- // add additional gas buffer to our estimation for safety
378
- const gasLimit = this.addGasBuffer(util.addHexPrefix(estimatedGasHex), blockGasLimit);
379
- return gasLimit;
380
- }
381
- }
382
-
383
- exports.TransactionFormatter = TransactionFormatter;
@@ -1,8 +0,0 @@
1
- 'use strict';
2
-
3
- exports.SignTypedDataVersion = void 0;
4
- (function (SignTypedDataVersion) {
5
- SignTypedDataVersion["V1"] = "V1";
6
- SignTypedDataVersion["V3"] = "V3";
7
- SignTypedDataVersion["V4"] = "V4";
8
- })(exports.SignTypedDataVersion || (exports.SignTypedDataVersion = {}));
@@ -1,93 +0,0 @@
1
- 'use strict';
2
-
3
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var util = require('@ethereumjs/util');
5
- var httpHelpers = require('@toruslabs/http-helpers');
6
- var converter = require('../../converter.js');
7
-
8
- function normalizeGWEIDecimalNumbers(n) {
9
- const numberAsWEIHex = converter.decGWEIToHexWEI(n);
10
- const numberAsGWEI = converter.hexWEIToDecGWEI(numberAsWEIHex).toString();
11
- return numberAsGWEI;
12
- }
13
- async function fetchEip1159GasEstimates(url) {
14
- const estimates = await httpHelpers.get(url);
15
- const normalizedEstimates = _objectSpread(_objectSpread({}, estimates), {}, {
16
- estimatedBaseFee: normalizeGWEIDecimalNumbers(estimates.estimatedBaseFee),
17
- low: _objectSpread(_objectSpread({}, estimates.low), {}, {
18
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxPriorityFeePerGas),
19
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.low.suggestedMaxFeePerGas)
20
- }),
21
- medium: _objectSpread(_objectSpread({}, estimates.medium), {}, {
22
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxPriorityFeePerGas),
23
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.medium.suggestedMaxFeePerGas)
24
- }),
25
- high: _objectSpread(_objectSpread({}, estimates.high), {}, {
26
- suggestedMaxPriorityFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxPriorityFeePerGas),
27
- suggestedMaxFeePerGas: normalizeGWEIDecimalNumbers(estimates.high.suggestedMaxFeePerGas)
28
- })
29
- });
30
- return normalizedEstimates;
31
- }
32
- /**
33
- * Hit the legacy MetaSwaps gasPrices estimate api and return the low, medium
34
- * high values from that API.
35
- */
36
- async function fetchLegacyGasPriceEstimates(url) {
37
- const result = await httpHelpers.get(url, {
38
- referrer: url,
39
- referrerPolicy: "no-referrer-when-downgrade",
40
- method: "GET",
41
- mode: "cors"
42
- });
43
- return {
44
- low: result.SafeGasPrice,
45
- medium: result.ProposeGasPrice,
46
- high: result.FastGasPrice
47
- };
48
- }
49
- function validateAddress(address, propertyName) {
50
- if (!address || typeof address !== "string" || !util.isValidAddress(address)) {
51
- throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
52
- }
53
- }
54
- async function validateTypedSignMessageDataV4(messageData, currentChainId) {
55
- validateAddress(messageData.from, "from");
56
- if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== "object" && typeof messageData.data !== "string") {
57
- throw new Error(`Invalid message "data": Must be a valid string or object.`);
58
- }
59
- let data;
60
- if (typeof messageData.data === "object") {
61
- data = messageData.data;
62
- } else {
63
- try {
64
- data = JSON.parse(messageData.data);
65
- } catch {
66
- throw new Error("Data must be passed as a valid JSON string.");
67
- }
68
- }
69
- if (!currentChainId) {
70
- throw new Error("Current chainId cannot be null or undefined.");
71
- }
72
- let {
73
- chainId
74
- } = data.domain;
75
- if (chainId) {
76
- if (typeof chainId === "string") {
77
- chainId = parseInt(chainId, chainId.startsWith("0x") ? 16 : 10);
78
- }
79
- const activeChainId = parseInt(currentChainId, 16);
80
- if (Number.isNaN(activeChainId)) {
81
- throw new Error(`Cannot sign messages for chainId "${chainId}", because Web3Auth is switching networks.`);
82
- }
83
- if (chainId !== activeChainId) {
84
- throw new Error(`Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`);
85
- }
86
- }
87
- }
88
-
89
- exports.fetchEip1159GasEstimates = fetchEip1159GasEstimates;
90
- exports.fetchLegacyGasPriceEstimates = fetchLegacyGasPriceEstimates;
91
- exports.normalizeGWEIDecimalNumbers = normalizeGWEIDecimalNumbers;
92
- exports.validateAddress = validateAddress;
93
- exports.validateTypedSignMessageDataV4 = validateTypedSignMessageDataV4;
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- var util = require('@ethereumjs/util');
4
- var bignumber_js = require('bignumber.js');
5
- var BN = require('bn.js');
6
-
7
- function bnLessThan(a, b) {
8
- if (a === null || a === undefined || b === null || b === undefined) {
9
- return null;
10
- }
11
- return new bignumber_js.BigNumber(a, 10).lt(b, 10);
12
- }
13
- function bnToHex(inputBn) {
14
- return util.addHexPrefix(inputBn.toString(16));
15
- }
16
- function hexToBn(inputHex) {
17
- if (BN.isBN(inputHex)) return inputHex;
18
- return new BN(util.stripHexPrefix(inputHex), 16);
19
- }
20
- function BnMultiplyByFraction(targetBN, numerator, denominator) {
21
- const numberBN = new BN(numerator);
22
- const denomBN = new BN(denominator);
23
- return targetBN.mul(numberBN).div(denomBN);
24
- }
25
-
26
- exports.BnMultiplyByFraction = BnMultiplyByFraction;
27
- exports.bnLessThan = bnLessThan;
28
- exports.bnToHex = bnToHex;
29
- exports.hexToBn = hexToBn;