@subwallet/extension-base 0.7.10-0 → 0.8.1-wr2x

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 (851) hide show
  1. package/background/KoniTypes.d.ts +662 -485
  2. package/background/KoniTypes.js +134 -51
  3. package/background/RequestBytesSign.d.ts +1 -1
  4. package/background/RequestExtrinsicSign.d.ts +1 -1
  5. package/background/errors/EvmProviderError.d.ts +6 -0
  6. package/background/errors/EvmProviderError.js +45 -0
  7. package/background/errors/ProviderError.d.ts +6 -0
  8. package/background/errors/ProviderError.js +32 -0
  9. package/background/errors/SWError.d.ts +12 -0
  10. package/background/errors/SWError.js +18 -0
  11. package/background/errors/TransactionError.d.ts +6 -0
  12. package/background/errors/TransactionError.js +57 -0
  13. package/background/handlers/Extension.d.ts +3 -1
  14. package/background/handlers/Extension.js +7 -11
  15. package/background/handlers/State.d.ts +5 -1
  16. package/background/handlers/State.js +53 -30
  17. package/background/handlers/Tabs.js +2 -2
  18. package/background/types.d.ts +20 -13
  19. package/background/warnings/SWWarning.d.ts +7 -0
  20. package/{errors/SubWalletProviderError.js → background/warnings/SWWarning.js} +4 -3
  21. package/background/warnings/TransactionWarning.d.ts +6 -0
  22. package/background/warnings/TransactionWarning.js +19 -0
  23. package/cjs/background/KoniTypes.js +134 -58
  24. package/cjs/background/errors/EvmProviderError.js +52 -0
  25. package/cjs/background/errors/EvmRpcError.js +21 -0
  26. package/cjs/background/errors/ProviderError.js +39 -0
  27. package/cjs/background/errors/SWError.js +25 -0
  28. package/cjs/background/errors/SubWalletProviderError.js +17 -0
  29. package/cjs/background/errors/TransactionError.js +63 -0
  30. package/cjs/background/handlers/Extension.js +7 -10
  31. package/cjs/background/handlers/State.js +56 -32
  32. package/cjs/background/handlers/Tabs.js +2 -2
  33. package/cjs/background/warnings/SWWarning.js +18 -0
  34. package/cjs/background/warnings/TransactionWarning.js +26 -0
  35. package/cjs/constants/ethereum.js +19 -0
  36. package/cjs/constants/i18n.js +32 -0
  37. package/cjs/constants/index.js +59 -0
  38. package/cjs/defaults.js +4 -2
  39. package/cjs/koni/api/coingecko.js +46 -0
  40. package/cjs/koni/api/donate.js +20 -0
  41. package/cjs/koni/api/dotsama/balance.js +724 -0
  42. package/cjs/koni/api/dotsama/crowdloan.js +145 -0
  43. package/cjs/koni/api/dotsama/parseTransaction.js +100 -0
  44. package/cjs/koni/api/dotsama/transfer.js +239 -0
  45. package/cjs/koni/api/dotsama/typeRegistry.js +13 -0
  46. package/cjs/koni/api/nft/acala_nft/index.js +161 -0
  47. package/cjs/koni/api/nft/bit.country/index.js +135 -0
  48. package/cjs/koni/api/nft/config.js +144 -0
  49. package/cjs/koni/api/nft/evm_nft/index.js +172 -0
  50. package/cjs/koni/api/nft/index.js +152 -0
  51. package/cjs/koni/api/nft/karura_nft/index.js +165 -0
  52. package/cjs/koni/api/nft/nft.js +96 -0
  53. package/cjs/koni/api/nft/quartz_nft/index.js +215 -0
  54. package/cjs/koni/api/nft/quartz_nft/protobuf.js +85 -0
  55. package/cjs/koni/api/nft/rmrk_nft/index.js +266 -0
  56. package/cjs/koni/api/nft/statemine_nft/index.js +152 -0
  57. package/cjs/koni/api/nft/transfer.js +146 -0
  58. package/cjs/koni/api/nft/unique_nft/index.js +200 -0
  59. package/cjs/koni/api/nft/unique_nft/protobuf.js +93 -0
  60. package/cjs/koni/api/nft/unique_nft/runtime_types.js +122 -0
  61. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +70 -0
  62. package/cjs/koni/api/nft/wasm_nft/index.js +297 -0
  63. package/cjs/koni/api/nft/wasm_nft/utils.js +19 -0
  64. package/cjs/koni/api/staking/bonding/amplitude.js +183 -0
  65. package/cjs/koni/api/staking/bonding/astar.js +458 -0
  66. package/cjs/koni/api/staking/bonding/index.js +104 -0
  67. package/cjs/koni/api/staking/bonding/paraChain.js +254 -0
  68. package/cjs/koni/api/staking/bonding/relayChain.js +349 -0
  69. package/cjs/koni/api/staking/bonding/utils.js +167 -0
  70. package/cjs/koni/api/staking/config.js +47 -0
  71. package/cjs/koni/api/staking/index.js +77 -0
  72. package/cjs/koni/api/staking/paraChain.js +226 -0
  73. package/cjs/koni/api/staking/relayChain.js +171 -0
  74. package/cjs/koni/api/staking/subsquidStaking.js +109 -0
  75. package/cjs/koni/api/staking/utils.js +17 -0
  76. package/cjs/koni/api/subquery/__generated__/DotSamaHistory.js +1 -0
  77. package/cjs/koni/api/subquery/subquery.js +21 -0
  78. package/cjs/koni/api/tokens/evm/balance.js +15 -0
  79. package/cjs/koni/api/tokens/evm/transfer.js +102 -0
  80. package/cjs/koni/api/tokens/evm/web3.js +17 -0
  81. package/cjs/koni/api/tokens/index.js +17 -0
  82. package/cjs/koni/api/tokens/wasm/index.js +77 -0
  83. package/cjs/koni/api/xcm/astar.js +160 -0
  84. package/cjs/koni/api/xcm/index.js +214 -0
  85. package/cjs/koni/api/xcm/moonbeamXcm.js +80 -0
  86. package/cjs/koni/api/xcm/statemintXcm.js +197 -0
  87. package/cjs/koni/api/xcm/substrateXcm.js +213 -0
  88. package/cjs/koni/api/xcm/utils.js +80 -0
  89. package/cjs/koni/background/cron.js +249 -0
  90. package/cjs/koni/background/events.js +14 -0
  91. package/cjs/koni/background/handlers/Extension.js +3113 -0
  92. package/cjs/koni/background/handlers/Mobile.js +138 -0
  93. package/cjs/koni/background/handlers/State.js +1483 -0
  94. package/cjs/koni/background/handlers/Tabs.js +797 -0
  95. package/cjs/koni/background/handlers/index.js +90 -0
  96. package/cjs/koni/background/subscription.js +305 -0
  97. package/cjs/koni/migration/Base.js +20 -0
  98. package/cjs/koni/migration/index.js +45 -0
  99. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +22 -0
  100. package/cjs/koni/migration/scripts/ClearOldStorage.js +24 -0
  101. package/cjs/koni/migration/scripts/RemoveWrongCrowdloan.js +19 -0
  102. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +36 -0
  103. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +21 -0
  104. package/cjs/koni/migration/scripts/index.js +22 -0
  105. package/cjs/koni/page/SubWalleEvmProvider.js +142 -0
  106. package/cjs/koni/page/index.js +16 -0
  107. package/cjs/packageInfo.js +1 -1
  108. package/cjs/page/index.js +3 -2
  109. package/cjs/services/balance-service/index.js +15 -0
  110. package/cjs/services/chain-service/constants.js +228 -0
  111. package/cjs/services/chain-service/handler/EvmChainHandler.js +144 -0
  112. package/cjs/services/chain-service/handler/SubstrateChainHandler.js +348 -0
  113. package/cjs/services/chain-service/handler/light-client/index.js +120 -0
  114. package/cjs/services/chain-service/handler/types.js +20 -0
  115. package/cjs/services/chain-service/heath-check/index.js +60 -0
  116. package/cjs/services/chain-service/helper/api-helper/chain/crust-maxwell.js +108 -0
  117. package/cjs/services/chain-service/helper/api-helper/chain/index.js +17 -0
  118. package/cjs/services/chain-service/helper/api-helper/index.js +35 -0
  119. package/cjs/services/chain-service/helper/api-helper/spec/acala.js +11 -0
  120. package/cjs/services/chain-service/helper/api-helper/spec/ajuna.js +22 -0
  121. package/cjs/services/chain-service/helper/api-helper/spec/altair.js +31 -0
  122. package/cjs/services/chain-service/helper/api-helper/spec/apron.js +24 -0
  123. package/cjs/services/chain-service/helper/api-helper/spec/ares-gladios.js +191 -0
  124. package/cjs/services/chain-service/helper/api-helper/spec/ares-parachain.js +192 -0
  125. package/cjs/services/chain-service/helper/api-helper/spec/astar.js +44 -0
  126. package/cjs/services/chain-service/helper/api-helper/spec/automata.js +43 -0
  127. package/cjs/services/chain-service/helper/api-helper/spec/basilisk.js +139 -0
  128. package/cjs/services/chain-service/helper/api-helper/spec/beresheet.js +12 -0
  129. package/cjs/services/chain-service/helper/api-helper/spec/bifrost-asgard.js +11 -0
  130. package/cjs/services/chain-service/helper/api-helper/spec/bifrost-parachain.js +11 -0
  131. package/cjs/services/chain-service/helper/api-helper/spec/bifrost.js +11 -0
  132. package/cjs/services/chain-service/helper/api-helper/spec/bitcountry-pioneer.js +11 -0
  133. package/cjs/services/chain-service/helper/api-helper/spec/bitcountry-rococo.js +122 -0
  134. package/cjs/services/chain-service/helper/api-helper/spec/bitcountry.js +84 -0
  135. package/cjs/services/chain-service/helper/api-helper/spec/canvas.js +31 -0
  136. package/cjs/services/chain-service/helper/api-helper/spec/centrifuge-chain.js +77 -0
  137. package/cjs/services/chain-service/helper/api-helper/spec/centrifuge.js +31 -0
  138. package/cjs/services/chain-service/helper/api-helper/spec/chainx.js +403 -0
  139. package/cjs/services/chain-service/helper/api-helper/spec/clover-rococo.js +68 -0
  140. package/cjs/services/chain-service/helper/api-helper/spec/clover.js +34 -0
  141. package/cjs/services/chain-service/helper/api-helper/spec/coinversation.js +24 -0
  142. package/cjs/services/chain-service/helper/api-helper/spec/competitors-club.js +84 -0
  143. package/cjs/services/chain-service/helper/api-helper/spec/crab.js +11 -0
  144. package/cjs/services/chain-service/helper/api-helper/spec/crown-sterling.js +55 -0
  145. package/cjs/services/chain-service/helper/api-helper/spec/crust.js +11 -0
  146. package/cjs/services/chain-service/helper/api-helper/spec/cumulus-test-parachain.js +24 -0
  147. package/cjs/services/chain-service/helper/api-helper/spec/darwinia.js +11 -0
  148. package/cjs/services/chain-service/helper/api-helper/spec/datahighway.js +240 -0
  149. package/cjs/services/chain-service/helper/api-helper/spec/dock-mainnet.js +16 -0
  150. package/cjs/services/chain-service/helper/api-helper/spec/dock-testnet.js +16 -0
  151. package/cjs/services/chain-service/helper/api-helper/spec/dolphin.js +29 -0
  152. package/cjs/services/chain-service/helper/api-helper/spec/dotmog.js +65 -0
  153. package/cjs/services/chain-service/helper/api-helper/spec/eave.js +416 -0
  154. package/cjs/services/chain-service/helper/api-helper/spec/edgeware.js +11 -0
  155. package/cjs/services/chain-service/helper/api-helper/spec/encointer-node-notee.js +75 -0
  156. package/cjs/services/chain-service/helper/api-helper/spec/encointer-node-teeproxy.js +52 -0
  157. package/cjs/services/chain-service/helper/api-helper/spec/encointer-para.js +79 -0
  158. package/cjs/services/chain-service/helper/api-helper/spec/equilibrium.js +109 -0
  159. package/cjs/services/chain-service/helper/api-helper/spec/fantour.js +70 -0
  160. package/cjs/services/chain-service/helper/api-helper/spec/galital-parachain.js +65 -0
  161. package/cjs/services/chain-service/helper/api-helper/spec/galital.js +70 -0
  162. package/cjs/services/chain-service/helper/api-helper/spec/galois.js +54 -0
  163. package/cjs/services/chain-service/helper/api-helper/spec/gamepower.js +71 -0
  164. package/cjs/services/chain-service/helper/api-helper/spec/genshiro.js +31 -0
  165. package/cjs/services/chain-service/helper/api-helper/spec/hanonycash.js +33 -0
  166. package/cjs/services/chain-service/helper/api-helper/spec/hydrate.js +59 -0
  167. package/cjs/services/chain-service/helper/api-helper/spec/idavoll.js +24 -0
  168. package/cjs/services/chain-service/helper/api-helper/spec/index.js +272 -0
  169. package/cjs/services/chain-service/helper/api-helper/spec/integritee.js +35 -0
  170. package/cjs/services/chain-service/helper/api-helper/spec/interbtc.js +60 -0
  171. package/cjs/services/chain-service/helper/api-helper/spec/ipse.js +113 -0
  172. package/cjs/services/chain-service/helper/api-helper/spec/jupiter-rococo.js +24 -0
  173. package/cjs/services/chain-service/helper/api-helper/spec/jupiter.js +70 -0
  174. package/cjs/services/chain-service/helper/api-helper/spec/khala.js +11 -0
  175. package/cjs/services/chain-service/helper/api-helper/spec/kilt.js +11 -0
  176. package/cjs/services/chain-service/helper/api-helper/spec/konomi.js +24 -0
  177. package/cjs/services/chain-service/helper/api-helper/spec/kpron.js +24 -0
  178. package/cjs/services/chain-service/helper/api-helper/spec/kulupu.js +64 -0
  179. package/cjs/services/chain-service/helper/api-helper/spec/kusari.js +45 -0
  180. package/cjs/services/chain-service/helper/api-helper/spec/kylin.js +36 -0
  181. package/cjs/services/chain-service/helper/api-helper/spec/laminar.js +11 -0
  182. package/cjs/services/chain-service/helper/api-helper/spec/litentry.js +24 -0
  183. package/cjs/services/chain-service/helper/api-helper/spec/mangata.js +20 -0
  184. package/cjs/services/chain-service/helper/api-helper/spec/manta.js +29 -0
  185. package/cjs/services/chain-service/helper/api-helper/spec/mathchain.js +54 -0
  186. package/cjs/services/chain-service/helper/api-helper/spec/moonbeam.js +11 -0
  187. package/cjs/services/chain-service/helper/api-helper/spec/moonsama-development.js +24 -0
  188. package/cjs/services/chain-service/helper/api-helper/spec/mybank.js +87 -0
  189. package/cjs/services/chain-service/helper/api-helper/spec/neatcoin.js +32 -0
  190. package/cjs/services/chain-service/helper/api-helper/spec/neumann.js +55 -0
  191. package/cjs/services/chain-service/helper/api-helper/spec/nftmart.js +134 -0
  192. package/cjs/services/chain-service/helper/api-helper/spec/nodle.js +53 -0
  193. package/cjs/services/chain-service/helper/api-helper/spec/opal.js +15 -0
  194. package/cjs/services/chain-service/helper/api-helper/spec/opportunity.js +12 -0
  195. package/cjs/services/chain-service/helper/api-helper/spec/origintrail.js +206 -0
  196. package/cjs/services/chain-service/helper/api-helper/spec/pangolin.js +11 -0
  197. package/cjs/services/chain-service/helper/api-helper/spec/pangoro.js +12 -0
  198. package/cjs/services/chain-service/helper/api-helper/spec/parallel.js +11 -0
  199. package/cjs/services/chain-service/helper/api-helper/spec/parami.js +21 -0
  200. package/cjs/services/chain-service/helper/api-helper/spec/phoenix.js +52 -0
  201. package/cjs/services/chain-service/helper/api-helper/spec/pichiu.js +36 -0
  202. package/cjs/services/chain-service/helper/api-helper/spec/plasm.js +54 -0
  203. package/cjs/services/chain-service/helper/api-helper/spec/polkadex.js +32 -0
  204. package/cjs/services/chain-service/helper/api-helper/spec/polkafoundry.js +43 -0
  205. package/cjs/services/chain-service/helper/api-helper/spec/polymesh.js +21 -0
  206. package/cjs/services/chain-service/helper/api-helper/spec/pontem.js +11 -0
  207. package/cjs/services/chain-service/helper/api-helper/spec/prism.js +24 -0
  208. package/cjs/services/chain-service/helper/api-helper/spec/quartz.js +15 -0
  209. package/cjs/services/chain-service/helper/api-helper/spec/realis.js +42 -0
  210. package/cjs/services/chain-service/helper/api-helper/spec/riochain.js +104 -0
  211. package/cjs/services/chain-service/helper/api-helper/spec/robonomics.js +41 -0
  212. package/cjs/services/chain-service/helper/api-helper/spec/shibuya.js +54 -0
  213. package/cjs/services/chain-service/helper/api-helper/spec/shiden.js +54 -0
  214. package/cjs/services/chain-service/helper/api-helper/spec/snowbridge.js +11 -0
  215. package/cjs/services/chain-service/helper/api-helper/spec/soraSubstrate.js +11 -0
  216. package/cjs/services/chain-service/helper/api-helper/spec/spanner.js +501 -0
  217. package/cjs/services/chain-service/helper/api-helper/spec/stafi.js +25 -0
  218. package/cjs/services/chain-service/helper/api-helper/spec/standard.js +12 -0
  219. package/cjs/services/chain-service/helper/api-helper/spec/subdao.js +21 -0
  220. package/cjs/services/chain-service/helper/api-helper/spec/subgame.js +185 -0
  221. package/cjs/services/chain-service/helper/api-helper/spec/subsocial.js +15 -0
  222. package/cjs/services/chain-service/helper/api-helper/spec/subspace.js +127 -0
  223. package/cjs/services/chain-service/helper/api-helper/spec/substrateContractsNode.js +23 -0
  224. package/cjs/services/chain-service/helper/api-helper/spec/swapdex.js +45 -0
  225. package/cjs/services/chain-service/helper/api-helper/spec/ternoa.js +95 -0
  226. package/cjs/services/chain-service/helper/api-helper/spec/trustbase.js +24 -0
  227. package/cjs/services/chain-service/helper/api-helper/spec/uart.js +289 -0
  228. package/cjs/services/chain-service/helper/api-helper/spec/unique.js +124 -0
  229. package/cjs/services/chain-service/helper/api-helper/spec/unitv.js +25 -0
  230. package/cjs/services/chain-service/helper/api-helper/spec/vln-rococo.js +109 -0
  231. package/cjs/services/chain-service/helper/api-helper/spec/vln.js +45 -0
  232. package/cjs/services/chain-service/helper/api-helper/spec/vodka.js +22 -0
  233. package/cjs/services/chain-service/helper/api-helper/spec/web3games.js +43 -0
  234. package/cjs/services/chain-service/helper/api-helper/spec/westlake.js +305 -0
  235. package/cjs/services/chain-service/helper/api-helper/spec/zCloak.js +46 -0
  236. package/cjs/services/chain-service/helper/api-helper/spec/zeitgeist.js +33 -0
  237. package/cjs/services/chain-service/helper/api-helper/spec/zenlink.js +57 -0
  238. package/cjs/services/chain-service/helper/api-helper/spec/zero.js +11 -0
  239. package/cjs/services/chain-service/helper/api-helper/util.js +25 -0
  240. package/cjs/services/chain-service/helper/index.js +24 -0
  241. package/cjs/services/chain-service/index.js +1004 -0
  242. package/cjs/services/chain-service/types.js +26 -0
  243. package/cjs/services/chain-service/utils.js +369 -0
  244. package/cjs/services/history-service/index.js +106 -0
  245. package/cjs/services/history-service/subsquid-multi-chain-history.js +255 -0
  246. package/cjs/services/notification-service/NotificationService.js +31 -0
  247. package/cjs/services/price-service/coingecko.js +46 -0
  248. package/cjs/services/price-service/index.js +64 -0
  249. package/cjs/services/request-service/constants.js +11 -0
  250. package/cjs/services/request-service/handler/AuthRequestHandler.js +269 -0
  251. package/cjs/services/request-service/handler/EvmRequestHandler.js +217 -0
  252. package/cjs/services/request-service/handler/MetadataRequestHandler.js +85 -0
  253. package/cjs/services/request-service/handler/PopupHandler.js +85 -0
  254. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +105 -0
  255. package/cjs/services/request-service/helper/index.js +58 -0
  256. package/cjs/services/request-service/index.js +162 -0
  257. package/cjs/services/request-service/types.js +1 -0
  258. package/cjs/services/setting-service/SettingService.js +38 -0
  259. package/cjs/services/storage-service/DatabaseService.js +230 -0
  260. package/cjs/services/storage-service/databases/index.js +46 -0
  261. package/cjs/services/storage-service/db-stores/Asset.js +20 -0
  262. package/cjs/services/storage-service/db-stores/Balance.js +57 -0
  263. package/cjs/services/storage-service/db-stores/BaseStore.js +29 -0
  264. package/cjs/services/storage-service/db-stores/BaseStoreWithAddress.js +28 -0
  265. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +33 -0
  266. package/cjs/services/storage-service/db-stores/BaseStoreWithChain.js +20 -0
  267. package/cjs/services/storage-service/db-stores/Chain.js +20 -0
  268. package/cjs/services/storage-service/db-stores/ChainStakingMetadata.js +38 -0
  269. package/cjs/services/storage-service/db-stores/Crowdloan.js +23 -0
  270. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +17 -0
  271. package/cjs/services/storage-service/db-stores/Migration.js +13 -0
  272. package/cjs/services/storage-service/db-stores/Nft.js +69 -0
  273. package/cjs/services/storage-service/db-stores/NftCollection.js +30 -0
  274. package/cjs/services/storage-service/db-stores/NominatorMetadata.js +30 -0
  275. package/cjs/services/storage-service/db-stores/Price.js +13 -0
  276. package/cjs/services/storage-service/db-stores/Staking.js +40 -0
  277. package/cjs/services/storage-service/db-stores/Transaction.js +49 -0
  278. package/cjs/services/storage-service/db-stores/index.js +76 -0
  279. package/cjs/services/transaction-service/helpers/index.js +23 -0
  280. package/cjs/services/transaction-service/index.js +606 -0
  281. package/cjs/services/transaction-service/types.js +1 -0
  282. package/cjs/services/transaction-service/utils.js +30 -0
  283. package/cjs/stores/AccountRef.js +18 -0
  284. package/cjs/stores/Application.js +28 -0
  285. package/cjs/stores/AssetSetting.js +19 -0
  286. package/cjs/stores/Authorize.js +18 -0
  287. package/cjs/stores/Balance.js +18 -0
  288. package/cjs/stores/Crowdloan.js +18 -0
  289. package/cjs/stores/CurrentAccountStore.js +18 -0
  290. package/cjs/stores/CustomEvmToken.js +18 -0
  291. package/cjs/stores/Keyring.js +39 -0
  292. package/cjs/stores/NetworkMap.js +18 -0
  293. package/cjs/stores/Nft.js +18 -0
  294. package/cjs/stores/NftCollection.js +18 -0
  295. package/cjs/stores/Price.js +18 -0
  296. package/cjs/stores/Settings.js +18 -0
  297. package/cjs/stores/Staking.js +18 -0
  298. package/cjs/stores/StakingReward.js +18 -0
  299. package/cjs/stores/SubscribableStore.js +33 -0
  300. package/cjs/stores/TransactionHistory.js +37 -0
  301. package/cjs/stores/TransactionHistoryV2.js +18 -0
  302. package/cjs/stores/TransactionHistoryV3.js +18 -0
  303. package/cjs/stores/index.js +8 -1
  304. package/cjs/utils/address.js +17 -0
  305. package/cjs/utils/eth/mergeTransactionAndSignature.js +22 -0
  306. package/cjs/utils/eth/parseTransaction/base.js +282 -0
  307. package/cjs/utils/eth/parseTransaction/index.js +229 -0
  308. package/cjs/utils/eth/parseTransactionData.js +284 -0
  309. package/cjs/utils/eth.js +76 -0
  310. package/cjs/utils/index.js +309 -1
  311. package/cjs/utils/keyring.js +57 -0
  312. package/cjs/utils/request.js +13 -0
  313. package/constants/i18n.d.ts +2 -0
  314. package/constants/i18n.js +25 -0
  315. package/constants/index.d.ts +25 -0
  316. package/constants/index.js +28 -0
  317. package/defaults.d.ts +3 -2
  318. package/defaults.js +3 -2
  319. package/koni/api/coingecko.d.ts +2 -0
  320. package/koni/api/coingecko.js +37 -0
  321. package/koni/api/donate.d.ts +3 -0
  322. package/koni/api/donate.js +13 -0
  323. package/koni/api/dotsama/balance.d.ts +7 -0
  324. package/koni/api/dotsama/balance.js +712 -0
  325. package/koni/api/dotsama/crowdloan.d.ts +7 -0
  326. package/koni/api/dotsama/crowdloan.js +130 -0
  327. package/koni/api/dotsama/parseTransaction.d.ts +3 -0
  328. package/koni/api/dotsama/parseTransaction.js +93 -0
  329. package/koni/api/dotsama/transfer.d.ts +20 -0
  330. package/koni/api/dotsama/transfer.js +227 -0
  331. package/koni/api/dotsama/typeRegistry.d.ts +3 -0
  332. package/koni/api/dotsama/typeRegistry.js +6 -0
  333. package/koni/api/nft/acala_nft/index.d.ts +18 -0
  334. package/koni/api/nft/acala_nft/index.js +150 -0
  335. package/koni/api/nft/bit.country/index.d.ts +12 -0
  336. package/koni/api/nft/bit.country/index.js +124 -0
  337. package/koni/api/nft/config.d.ts +57 -0
  338. package/koni/api/nft/config.js +110 -0
  339. package/koni/api/nft/evm_nft/index.d.ts +13 -0
  340. package/koni/api/nft/evm_nft/index.js +164 -0
  341. package/koni/api/nft/index.d.ts +22 -0
  342. package/koni/api/nft/index.js +143 -0
  343. package/koni/api/nft/karura_nft/index.d.ts +18 -0
  344. package/koni/api/nft/karura_nft/index.js +153 -0
  345. package/koni/api/nft/nft.d.ts +31 -0
  346. package/koni/api/nft/nft.js +89 -0
  347. package/koni/api/nft/quartz_nft/index.d.ts +62 -0
  348. package/koni/api/nft/quartz_nft/index.js +204 -0
  349. package/koni/api/nft/quartz_nft/protobuf.d.ts +3 -0
  350. package/koni/api/nft/quartz_nft/protobuf.js +78 -0
  351. package/koni/api/nft/rmrk_nft/index.d.ts +10 -0
  352. package/koni/api/nft/rmrk_nft/index.js +258 -0
  353. package/koni/api/nft/statemine_nft/index.d.ts +18 -0
  354. package/koni/api/nft/statemine_nft/index.js +141 -0
  355. package/koni/api/nft/transfer.d.ts +15 -0
  356. package/koni/api/nft/transfer.js +129 -0
  357. package/koni/api/nft/unique_nft/index.d.ts +54 -0
  358. package/koni/api/nft/unique_nft/index.js +191 -0
  359. package/koni/api/nft/unique_nft/protobuf.d.ts +3 -0
  360. package/koni/api/nft/unique_nft/protobuf.js +86 -0
  361. package/koni/api/nft/unique_nft/runtime_types.d.ts +3 -0
  362. package/koni/api/nft/unique_nft/runtime_types.js +115 -0
  363. package/koni/api/nft/unique_nft/uniqueNftV2.d.ts +9 -0
  364. package/koni/api/nft/unique_nft/uniqueNftV2.js +62 -0
  365. package/koni/api/nft/wasm_nft/index.d.ts +17 -0
  366. package/koni/api/nft/wasm_nft/index.js +289 -0
  367. package/koni/api/nft/wasm_nft/utils.d.ts +5 -0
  368. package/koni/api/nft/wasm_nft/utils.js +8 -0
  369. package/koni/api/staking/bonding/amplitude.d.ts +11 -0
  370. package/koni/api/staking/bonding/amplitude.js +170 -0
  371. package/koni/api/staking/bonding/astar.d.ts +19 -0
  372. package/koni/api/staking/bonding/astar.js +436 -0
  373. package/koni/api/staking/bonding/index.d.ts +12 -0
  374. package/koni/api/staking/bonding/index.js +90 -0
  375. package/koni/api/staking/bonding/paraChain.d.ts +12 -0
  376. package/koni/api/staking/bonding/paraChain.js +240 -0
  377. package/koni/api/staking/bonding/relayChain.d.ts +32 -0
  378. package/koni/api/staking/bonding/relayChain.js +329 -0
  379. package/koni/api/staking/bonding/utils.d.ts +135 -0
  380. package/koni/api/staking/bonding/utils.js +144 -0
  381. package/koni/api/staking/config.d.ts +3 -0
  382. package/koni/api/staking/config.js +38 -0
  383. package/koni/api/staking/index.d.ts +6 -0
  384. package/koni/api/staking/index.js +67 -0
  385. package/koni/api/staking/paraChain.d.ts +7 -0
  386. package/koni/api/staking/paraChain.js +216 -0
  387. package/koni/api/staking/relayChain.d.ts +6 -0
  388. package/koni/api/staking/relayChain.js +161 -0
  389. package/koni/api/staking/subsquidStaking.d.ts +3 -0
  390. package/koni/api/staking/subsquidStaking.js +101 -0
  391. package/koni/api/staking/utils.d.ts +2 -0
  392. package/koni/api/staking/utils.js +11 -0
  393. package/koni/api/subquery/__generated__/DotSamaHistory.d.ts +58 -0
  394. package/koni/api/subquery/__generated__/DotSamaHistory.js +1 -0
  395. package/koni/api/subquery/subquery.d.ts +2 -0
  396. package/koni/api/subquery/subquery.js +14 -0
  397. package/koni/api/tokens/evm/balance.d.ts +2 -0
  398. package/koni/api/tokens/evm/balance.js +9 -0
  399. package/koni/api/tokens/evm/transfer.d.ts +17 -0
  400. package/koni/api/tokens/evm/transfer.js +91 -0
  401. package/koni/api/tokens/evm/web3.d.ts +3 -0
  402. package/koni/api/tokens/evm/web3.js +9 -0
  403. package/koni/api/tokens/index.d.ts +1 -0
  404. package/koni/api/tokens/index.js +11 -0
  405. package/koni/api/tokens/wasm/index.d.ts +9 -0
  406. package/koni/api/tokens/wasm/index.js +68 -0
  407. package/koni/api/xcm/astar.d.ts +6 -0
  408. package/koni/api/xcm/astar.js +154 -0
  409. package/koni/api/xcm/index.d.ts +30 -0
  410. package/koni/api/xcm/index.js +203 -0
  411. package/koni/api/xcm/moonbeamXcm.d.ts +6 -0
  412. package/koni/api/xcm/moonbeamXcm.js +74 -0
  413. package/koni/api/xcm/statemintXcm.d.ts +6 -0
  414. package/koni/api/xcm/statemintXcm.js +190 -0
  415. package/koni/api/xcm/substrateXcm.d.ts +6 -0
  416. package/koni/api/xcm/substrateXcm.js +206 -0
  417. package/koni/api/xcm/utils.d.ts +12 -0
  418. package/koni/api/xcm/utils.js +68 -0
  419. package/koni/background/cron.d.ts +39 -0
  420. package/koni/background/cron.js +236 -0
  421. package/koni/background/events.d.ts +1 -0
  422. package/koni/background/events.js +7 -0
  423. package/koni/background/handlers/Extension.d.ts +185 -0
  424. package/koni/background/handlers/Extension.js +3038 -0
  425. package/koni/background/handlers/Mobile.d.ts +21 -0
  426. package/koni/background/handlers/Mobile.js +127 -0
  427. package/koni/background/handlers/State.d.ts +230 -0
  428. package/koni/background/handlers/State.js +1454 -0
  429. package/koni/background/handlers/Tabs.d.ts +47 -0
  430. package/koni/background/handlers/Tabs.js +746 -0
  431. package/koni/background/handlers/index.d.ts +13 -0
  432. package/koni/background/handlers/index.js +76 -0
  433. package/koni/background/subscription.d.ts +32 -0
  434. package/koni/background/subscription.js +287 -0
  435. package/koni/migration/Base.d.ts +8 -0
  436. package/koni/migration/Base.js +13 -0
  437. package/koni/migration/index.d.ts +7 -0
  438. package/koni/migration/index.js +37 -0
  439. package/koni/migration/scripts/ChangeRouteToHome.d.ts +4 -0
  440. package/koni/migration/scripts/ChangeRouteToHome.js +14 -0
  441. package/koni/migration/scripts/ClearOldStorage.d.ts +4 -0
  442. package/koni/migration/scripts/ClearOldStorage.js +16 -0
  443. package/koni/migration/scripts/RemoveWrongCrowdloan.d.ts +4 -0
  444. package/koni/migration/scripts/RemoveWrongCrowdloan.js +11 -0
  445. package/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.d.ts +4 -0
  446. package/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +27 -0
  447. package/koni/migration/scripts/ResetTransactionHistoryEventIdx.d.ts +4 -0
  448. package/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +13 -0
  449. package/koni/migration/scripts/index.d.ts +3 -0
  450. package/koni/migration/scripts/index.js +15 -0
  451. package/koni/page/SubWalleEvmProvider.d.ts +27 -0
  452. package/koni/page/SubWalleEvmProvider.js +132 -0
  453. package/koni/page/index.d.ts +2 -0
  454. package/koni/page/index.js +9 -0
  455. package/package.json +1441 -10
  456. package/packageInfo.js +1 -1
  457. package/page/index.js +3 -2
  458. package/services/balance-service/index.d.ts +7 -0
  459. package/services/balance-service/index.js +8 -0
  460. package/services/chain-service/constants.d.ts +85 -0
  461. package/services/chain-service/constants.js +208 -0
  462. package/services/chain-service/handler/EvmChainHandler.d.ts +16 -0
  463. package/services/chain-service/handler/EvmChainHandler.js +136 -0
  464. package/services/chain-service/handler/SubstrateChainHandler.d.ts +21 -0
  465. package/services/chain-service/handler/SubstrateChainHandler.js +340 -0
  466. package/services/chain-service/handler/light-client/index.d.ts +4 -0
  467. package/services/chain-service/handler/light-client/index.js +111 -0
  468. package/services/chain-service/handler/types.d.ts +26 -0
  469. package/services/chain-service/handler/types.js +14 -0
  470. package/services/chain-service/heath-check/index.d.ts +3 -0
  471. package/services/chain-service/heath-check/index.js +50 -0
  472. package/services/chain-service/helper/api-helper/chain/crust-maxwell.d.ts +98 -0
  473. package/services/chain-service/helper/api-helper/chain/crust-maxwell.js +103 -0
  474. package/services/chain-service/helper/api-helper/chain/index.d.ts +1943 -0
  475. package/services/chain-service/helper/api-helper/chain/index.js +11 -0
  476. package/services/chain-service/helper/api-helper/index.d.ts +7 -0
  477. package/services/chain-service/helper/api-helper/index.js +18 -0
  478. package/services/chain-service/helper/api-helper/spec/acala.d.ts +42 -0
  479. package/services/chain-service/helper/api-helper/spec/acala.js +5 -0
  480. package/services/chain-service/helper/api-helper/spec/ajuna.d.ts +3 -0
  481. package/services/chain-service/helper/api-helper/spec/ajuna.js +15 -0
  482. package/services/chain-service/helper/api-helper/spec/altair.d.ts +3 -0
  483. package/services/chain-service/helper/api-helper/spec/altair.js +24 -0
  484. package/services/chain-service/helper/api-helper/spec/apron.d.ts +3 -0
  485. package/services/chain-service/helper/api-helper/spec/apron.js +17 -0
  486. package/services/chain-service/helper/api-helper/spec/ares-gladios.d.ts +3 -0
  487. package/services/chain-service/helper/api-helper/spec/ares-gladios.js +184 -0
  488. package/services/chain-service/helper/api-helper/spec/ares-parachain.d.ts +3 -0
  489. package/services/chain-service/helper/api-helper/spec/ares-parachain.js +185 -0
  490. package/services/chain-service/helper/api-helper/spec/astar.d.ts +3 -0
  491. package/services/chain-service/helper/api-helper/spec/astar.js +37 -0
  492. package/services/chain-service/helper/api-helper/spec/automata.d.ts +3 -0
  493. package/services/chain-service/helper/api-helper/spec/automata.js +36 -0
  494. package/services/chain-service/helper/api-helper/spec/basilisk.d.ts +3 -0
  495. package/services/chain-service/helper/api-helper/spec/basilisk.js +132 -0
  496. package/services/chain-service/helper/api-helper/spec/beresheet.d.ts +3 -0
  497. package/services/chain-service/helper/api-helper/spec/beresheet.js +9 -0
  498. package/services/chain-service/helper/api-helper/spec/bifrost-asgard.d.ts +3 -0
  499. package/services/chain-service/helper/api-helper/spec/bifrost-asgard.js +5 -0
  500. package/services/chain-service/helper/api-helper/spec/bifrost-parachain.d.ts +3 -0
  501. package/services/chain-service/helper/api-helper/spec/bifrost-parachain.js +5 -0
  502. package/services/chain-service/helper/api-helper/spec/bifrost.d.ts +3 -0
  503. package/services/chain-service/helper/api-helper/spec/bifrost.js +5 -0
  504. package/services/chain-service/helper/api-helper/spec/bitcountry-pioneer.d.ts +2 -0
  505. package/services/chain-service/helper/api-helper/spec/bitcountry-pioneer.js +5 -0
  506. package/services/chain-service/helper/api-helper/spec/bitcountry-rococo.d.ts +3 -0
  507. package/services/chain-service/helper/api-helper/spec/bitcountry-rococo.js +115 -0
  508. package/services/chain-service/helper/api-helper/spec/bitcountry.d.ts +3 -0
  509. package/services/chain-service/helper/api-helper/spec/bitcountry.js +77 -0
  510. package/services/chain-service/helper/api-helper/spec/canvas.d.ts +3 -0
  511. package/services/chain-service/helper/api-helper/spec/canvas.js +24 -0
  512. package/services/chain-service/helper/api-helper/spec/centrifuge-chain.d.ts +3 -0
  513. package/services/chain-service/helper/api-helper/spec/centrifuge-chain.js +70 -0
  514. package/services/chain-service/helper/api-helper/spec/centrifuge.d.ts +3 -0
  515. package/services/chain-service/helper/api-helper/spec/centrifuge.js +24 -0
  516. package/services/chain-service/helper/api-helper/spec/chainx.d.ts +3 -0
  517. package/services/chain-service/helper/api-helper/spec/chainx.js +396 -0
  518. package/services/chain-service/helper/api-helper/spec/clover-rococo.d.ts +3 -0
  519. package/services/chain-service/helper/api-helper/spec/clover-rococo.js +61 -0
  520. package/services/chain-service/helper/api-helper/spec/clover.d.ts +3 -0
  521. package/services/chain-service/helper/api-helper/spec/clover.js +27 -0
  522. package/services/chain-service/helper/api-helper/spec/coinversation.d.ts +3 -0
  523. package/services/chain-service/helper/api-helper/spec/coinversation.js +17 -0
  524. package/services/chain-service/helper/api-helper/spec/competitors-club.d.ts +3 -0
  525. package/services/chain-service/helper/api-helper/spec/competitors-club.js +77 -0
  526. package/services/chain-service/helper/api-helper/spec/crab.d.ts +2 -0
  527. package/services/chain-service/helper/api-helper/spec/crab.js +5 -0
  528. package/services/chain-service/helper/api-helper/spec/crown-sterling.d.ts +3 -0
  529. package/services/chain-service/helper/api-helper/spec/crown-sterling.js +48 -0
  530. package/services/chain-service/helper/api-helper/spec/crust.d.ts +3 -0
  531. package/services/chain-service/helper/api-helper/spec/crust.js +5 -0
  532. package/services/chain-service/helper/api-helper/spec/cumulus-test-parachain.d.ts +3 -0
  533. package/services/chain-service/helper/api-helper/spec/cumulus-test-parachain.js +17 -0
  534. package/services/chain-service/helper/api-helper/spec/darwinia.d.ts +2 -0
  535. package/services/chain-service/helper/api-helper/spec/darwinia.js +5 -0
  536. package/services/chain-service/helper/api-helper/spec/datahighway.d.ts +3 -0
  537. package/services/chain-service/helper/api-helper/spec/datahighway.js +233 -0
  538. package/services/chain-service/helper/api-helper/spec/dock-mainnet.d.ts +3 -0
  539. package/services/chain-service/helper/api-helper/spec/dock-mainnet.js +9 -0
  540. package/services/chain-service/helper/api-helper/spec/dock-testnet.d.ts +3 -0
  541. package/services/chain-service/helper/api-helper/spec/dock-testnet.js +9 -0
  542. package/services/chain-service/helper/api-helper/spec/dolphin.d.ts +3 -0
  543. package/services/chain-service/helper/api-helper/spec/dolphin.js +22 -0
  544. package/services/chain-service/helper/api-helper/spec/dotmog.d.ts +3 -0
  545. package/services/chain-service/helper/api-helper/spec/dotmog.js +58 -0
  546. package/services/chain-service/helper/api-helper/spec/eave.d.ts +3 -0
  547. package/services/chain-service/helper/api-helper/spec/eave.js +409 -0
  548. package/services/chain-service/helper/api-helper/spec/edgeware.d.ts +3 -0
  549. package/services/chain-service/helper/api-helper/spec/edgeware.js +7 -0
  550. package/services/chain-service/helper/api-helper/spec/encointer-node-notee.d.ts +3 -0
  551. package/services/chain-service/helper/api-helper/spec/encointer-node-notee.js +68 -0
  552. package/services/chain-service/helper/api-helper/spec/encointer-node-teeproxy.d.ts +3 -0
  553. package/services/chain-service/helper/api-helper/spec/encointer-node-teeproxy.js +45 -0
  554. package/services/chain-service/helper/api-helper/spec/encointer-para.d.ts +3 -0
  555. package/services/chain-service/helper/api-helper/spec/encointer-para.js +72 -0
  556. package/services/chain-service/helper/api-helper/spec/equilibrium.d.ts +8 -0
  557. package/services/chain-service/helper/api-helper/spec/equilibrium.js +97 -0
  558. package/services/chain-service/helper/api-helper/spec/fantour.d.ts +3 -0
  559. package/services/chain-service/helper/api-helper/spec/fantour.js +63 -0
  560. package/services/chain-service/helper/api-helper/spec/galital-parachain.d.ts +3 -0
  561. package/services/chain-service/helper/api-helper/spec/galital-parachain.js +58 -0
  562. package/services/chain-service/helper/api-helper/spec/galital.d.ts +3 -0
  563. package/services/chain-service/helper/api-helper/spec/galital.js +63 -0
  564. package/services/chain-service/helper/api-helper/spec/galois.d.ts +3 -0
  565. package/services/chain-service/helper/api-helper/spec/galois.js +47 -0
  566. package/services/chain-service/helper/api-helper/spec/gamepower.d.ts +3 -0
  567. package/services/chain-service/helper/api-helper/spec/gamepower.js +64 -0
  568. package/services/chain-service/helper/api-helper/spec/genshiro.d.ts +3 -0
  569. package/services/chain-service/helper/api-helper/spec/genshiro.js +24 -0
  570. package/services/chain-service/helper/api-helper/spec/hanonycash.d.ts +3 -0
  571. package/services/chain-service/helper/api-helper/spec/hanonycash.js +26 -0
  572. package/services/chain-service/helper/api-helper/spec/hydrate.d.ts +3 -0
  573. package/services/chain-service/helper/api-helper/spec/hydrate.js +52 -0
  574. package/services/chain-service/helper/api-helper/spec/idavoll.d.ts +3 -0
  575. package/services/chain-service/helper/api-helper/spec/idavoll.js +17 -0
  576. package/services/chain-service/helper/api-helper/spec/index.d.ts +3 -0
  577. package/services/chain-service/helper/api-helper/spec/index.js +264 -0
  578. package/services/chain-service/helper/api-helper/spec/integritee.d.ts +3 -0
  579. package/services/chain-service/helper/api-helper/spec/integritee.js +28 -0
  580. package/services/chain-service/helper/api-helper/spec/interbtc.d.ts +7 -0
  581. package/services/chain-service/helper/api-helper/spec/interbtc.js +50 -0
  582. package/services/chain-service/helper/api-helper/spec/ipse.d.ts +3 -0
  583. package/services/chain-service/helper/api-helper/spec/ipse.js +106 -0
  584. package/services/chain-service/helper/api-helper/spec/jupiter-rococo.d.ts +3 -0
  585. package/services/chain-service/helper/api-helper/spec/jupiter-rococo.js +17 -0
  586. package/services/chain-service/helper/api-helper/spec/jupiter.d.ts +3 -0
  587. package/services/chain-service/helper/api-helper/spec/jupiter.js +63 -0
  588. package/services/chain-service/helper/api-helper/spec/khala.d.ts +3 -0
  589. package/services/chain-service/helper/api-helper/spec/khala.js +5 -0
  590. package/services/chain-service/helper/api-helper/spec/kilt.d.ts +3 -0
  591. package/services/chain-service/helper/api-helper/spec/kilt.js +5 -0
  592. package/services/chain-service/helper/api-helper/spec/konomi.d.ts +3 -0
  593. package/services/chain-service/helper/api-helper/spec/konomi.js +17 -0
  594. package/services/chain-service/helper/api-helper/spec/kpron.d.ts +3 -0
  595. package/services/chain-service/helper/api-helper/spec/kpron.js +17 -0
  596. package/services/chain-service/helper/api-helper/spec/kulupu.d.ts +3 -0
  597. package/services/chain-service/helper/api-helper/spec/kulupu.js +57 -0
  598. package/services/chain-service/helper/api-helper/spec/kusari.d.ts +3 -0
  599. package/services/chain-service/helper/api-helper/spec/kusari.js +38 -0
  600. package/services/chain-service/helper/api-helper/spec/kylin.d.ts +3 -0
  601. package/services/chain-service/helper/api-helper/spec/kylin.js +29 -0
  602. package/services/chain-service/helper/api-helper/spec/laminar.d.ts +3 -0
  603. package/services/chain-service/helper/api-helper/spec/laminar.js +5 -0
  604. package/services/chain-service/helper/api-helper/spec/litentry.d.ts +3 -0
  605. package/services/chain-service/helper/api-helper/spec/litentry.js +17 -0
  606. package/services/chain-service/helper/api-helper/spec/mangata.d.ts +3 -0
  607. package/services/chain-service/helper/api-helper/spec/mangata.js +13 -0
  608. package/services/chain-service/helper/api-helper/spec/manta.d.ts +3 -0
  609. package/services/chain-service/helper/api-helper/spec/manta.js +22 -0
  610. package/services/chain-service/helper/api-helper/spec/mathchain.d.ts +3 -0
  611. package/services/chain-service/helper/api-helper/spec/mathchain.js +47 -0
  612. package/services/chain-service/helper/api-helper/spec/moonbeam.d.ts +2 -0
  613. package/services/chain-service/helper/api-helper/spec/moonbeam.js +5 -0
  614. package/services/chain-service/helper/api-helper/spec/moonsama-development.d.ts +3 -0
  615. package/services/chain-service/helper/api-helper/spec/moonsama-development.js +17 -0
  616. package/services/chain-service/helper/api-helper/spec/mybank.d.ts +3 -0
  617. package/services/chain-service/helper/api-helper/spec/mybank.js +80 -0
  618. package/services/chain-service/helper/api-helper/spec/neatcoin.d.ts +3 -0
  619. package/services/chain-service/helper/api-helper/spec/neatcoin.js +25 -0
  620. package/services/chain-service/helper/api-helper/spec/neumann.d.ts +3 -0
  621. package/services/chain-service/helper/api-helper/spec/neumann.js +48 -0
  622. package/services/chain-service/helper/api-helper/spec/nftmart.d.ts +3 -0
  623. package/services/chain-service/helper/api-helper/spec/nftmart.js +127 -0
  624. package/services/chain-service/helper/api-helper/spec/nodle.d.ts +3 -0
  625. package/services/chain-service/helper/api-helper/spec/nodle.js +46 -0
  626. package/services/chain-service/helper/api-helper/spec/opal.d.ts +3 -0
  627. package/services/chain-service/helper/api-helper/spec/opal.js +9 -0
  628. package/services/chain-service/helper/api-helper/spec/opportunity.d.ts +3 -0
  629. package/services/chain-service/helper/api-helper/spec/opportunity.js +5 -0
  630. package/services/chain-service/helper/api-helper/spec/origintrail.d.ts +5 -0
  631. package/services/chain-service/helper/api-helper/spec/origintrail.js +198 -0
  632. package/services/chain-service/helper/api-helper/spec/pangolin.d.ts +2 -0
  633. package/services/chain-service/helper/api-helper/spec/pangolin.js +5 -0
  634. package/services/chain-service/helper/api-helper/spec/pangoro.d.ts +2 -0
  635. package/services/chain-service/helper/api-helper/spec/pangoro.js +7 -0
  636. package/services/chain-service/helper/api-helper/spec/parallel.d.ts +14 -0
  637. package/services/chain-service/helper/api-helper/spec/parallel.js +5 -0
  638. package/services/chain-service/helper/api-helper/spec/parami.d.ts +3 -0
  639. package/services/chain-service/helper/api-helper/spec/parami.js +14 -0
  640. package/services/chain-service/helper/api-helper/spec/phoenix.d.ts +3 -0
  641. package/services/chain-service/helper/api-helper/spec/phoenix.js +45 -0
  642. package/services/chain-service/helper/api-helper/spec/pichiu.d.ts +3 -0
  643. package/services/chain-service/helper/api-helper/spec/pichiu.js +29 -0
  644. package/services/chain-service/helper/api-helper/spec/plasm.d.ts +3 -0
  645. package/services/chain-service/helper/api-helper/spec/plasm.js +47 -0
  646. package/services/chain-service/helper/api-helper/spec/polkadex.d.ts +3 -0
  647. package/services/chain-service/helper/api-helper/spec/polkadex.js +25 -0
  648. package/services/chain-service/helper/api-helper/spec/polkafoundry.d.ts +3 -0
  649. package/services/chain-service/helper/api-helper/spec/polkafoundry.js +36 -0
  650. package/services/chain-service/helper/api-helper/spec/polymesh.d.ts +3 -0
  651. package/services/chain-service/helper/api-helper/spec/polymesh.js +13 -0
  652. package/services/chain-service/helper/api-helper/spec/pontem.d.ts +2 -0
  653. package/services/chain-service/helper/api-helper/spec/pontem.js +5 -0
  654. package/services/chain-service/helper/api-helper/spec/prism.d.ts +3 -0
  655. package/services/chain-service/helper/api-helper/spec/prism.js +17 -0
  656. package/services/chain-service/helper/api-helper/spec/quartz.d.ts +3 -0
  657. package/services/chain-service/helper/api-helper/spec/quartz.js +9 -0
  658. package/services/chain-service/helper/api-helper/spec/realis.d.ts +3 -0
  659. package/services/chain-service/helper/api-helper/spec/realis.js +35 -0
  660. package/services/chain-service/helper/api-helper/spec/riochain.d.ts +3 -0
  661. package/services/chain-service/helper/api-helper/spec/riochain.js +97 -0
  662. package/services/chain-service/helper/api-helper/spec/robonomics.d.ts +3 -0
  663. package/services/chain-service/helper/api-helper/spec/robonomics.js +34 -0
  664. package/services/chain-service/helper/api-helper/spec/shibuya.d.ts +3 -0
  665. package/services/chain-service/helper/api-helper/spec/shibuya.js +47 -0
  666. package/services/chain-service/helper/api-helper/spec/shiden.d.ts +3 -0
  667. package/services/chain-service/helper/api-helper/spec/shiden.js +47 -0
  668. package/services/chain-service/helper/api-helper/spec/snowbridge.d.ts +2 -0
  669. package/services/chain-service/helper/api-helper/spec/snowbridge.js +5 -0
  670. package/services/chain-service/helper/api-helper/spec/soraSubstrate.d.ts +3 -0
  671. package/services/chain-service/helper/api-helper/spec/soraSubstrate.js +5 -0
  672. package/services/chain-service/helper/api-helper/spec/spanner.d.ts +3 -0
  673. package/services/chain-service/helper/api-helper/spec/spanner.js +494 -0
  674. package/services/chain-service/helper/api-helper/spec/stafi.d.ts +3 -0
  675. package/services/chain-service/helper/api-helper/spec/stafi.js +18 -0
  676. package/services/chain-service/helper/api-helper/spec/standard.d.ts +3 -0
  677. package/services/chain-service/helper/api-helper/spec/standard.js +5 -0
  678. package/services/chain-service/helper/api-helper/spec/subdao.d.ts +3 -0
  679. package/services/chain-service/helper/api-helper/spec/subdao.js +14 -0
  680. package/services/chain-service/helper/api-helper/spec/subgame.d.ts +3 -0
  681. package/services/chain-service/helper/api-helper/spec/subgame.js +178 -0
  682. package/services/chain-service/helper/api-helper/spec/subsocial.d.ts +2 -0
  683. package/services/chain-service/helper/api-helper/spec/subsocial.js +8 -0
  684. package/services/chain-service/helper/api-helper/spec/subspace.d.ts +0 -0
  685. package/services/chain-service/helper/api-helper/spec/subspace.js +126 -0
  686. package/services/chain-service/helper/api-helper/spec/substrateContractsNode.d.ts +3 -0
  687. package/services/chain-service/helper/api-helper/spec/substrateContractsNode.js +16 -0
  688. package/services/chain-service/helper/api-helper/spec/swapdex.d.ts +3 -0
  689. package/services/chain-service/helper/api-helper/spec/swapdex.js +38 -0
  690. package/services/chain-service/helper/api-helper/spec/ternoa.d.ts +3 -0
  691. package/services/chain-service/helper/api-helper/spec/ternoa.js +88 -0
  692. package/services/chain-service/helper/api-helper/spec/trustbase.d.ts +3 -0
  693. package/services/chain-service/helper/api-helper/spec/trustbase.js +17 -0
  694. package/services/chain-service/helper/api-helper/spec/uart.d.ts +3 -0
  695. package/services/chain-service/helper/api-helper/spec/uart.js +282 -0
  696. package/services/chain-service/helper/api-helper/spec/unique.d.ts +3 -0
  697. package/services/chain-service/helper/api-helper/spec/unique.js +117 -0
  698. package/services/chain-service/helper/api-helper/spec/unitv.d.ts +3 -0
  699. package/services/chain-service/helper/api-helper/spec/unitv.js +18 -0
  700. package/services/chain-service/helper/api-helper/spec/vln-rococo.d.ts +3 -0
  701. package/services/chain-service/helper/api-helper/spec/vln-rococo.js +102 -0
  702. package/services/chain-service/helper/api-helper/spec/vln.d.ts +3 -0
  703. package/services/chain-service/helper/api-helper/spec/vln.js +38 -0
  704. package/services/chain-service/helper/api-helper/spec/vodka.d.ts +3 -0
  705. package/services/chain-service/helper/api-helper/spec/vodka.js +15 -0
  706. package/services/chain-service/helper/api-helper/spec/web3games.d.ts +3 -0
  707. package/services/chain-service/helper/api-helper/spec/web3games.js +36 -0
  708. package/services/chain-service/helper/api-helper/spec/westlake.d.ts +3 -0
  709. package/services/chain-service/helper/api-helper/spec/westlake.js +298 -0
  710. package/services/chain-service/helper/api-helper/spec/zCloak.d.ts +3 -0
  711. package/services/chain-service/helper/api-helper/spec/zCloak.js +39 -0
  712. package/services/chain-service/helper/api-helper/spec/zeitgeist.d.ts +3 -0
  713. package/services/chain-service/helper/api-helper/spec/zeitgeist.js +24 -0
  714. package/services/chain-service/helper/api-helper/spec/zenlink.d.ts +3 -0
  715. package/services/chain-service/helper/api-helper/spec/zenlink.js +50 -0
  716. package/services/chain-service/helper/api-helper/spec/zero.d.ts +3 -0
  717. package/services/chain-service/helper/api-helper/spec/zero.js +5 -0
  718. package/services/chain-service/helper/api-helper/util.d.ts +5 -0
  719. package/services/chain-service/helper/api-helper/util.js +15 -0
  720. package/services/chain-service/helper/erc20_abi.json +224 -0
  721. package/services/chain-service/helper/erc721_abi.json +384 -0
  722. package/services/chain-service/helper/index.d.ts +5 -0
  723. package/services/chain-service/helper/index.js +13 -0
  724. package/services/chain-service/helper/psp22_abi.json +967 -0
  725. package/services/chain-service/helper/psp34_abi.json +1988 -0
  726. package/services/chain-service/helper/test_erc721_abi.json +393 -0
  727. package/services/chain-service/index.d.ts +85 -0
  728. package/services/chain-service/index.js +992 -0
  729. package/services/chain-service/types.d.ts +110 -0
  730. package/services/chain-service/types.js +17 -0
  731. package/services/chain-service/utils.d.ts +66 -0
  732. package/services/chain-service/utils.js +303 -0
  733. package/services/history-service/index.d.ts +21 -0
  734. package/services/history-service/index.js +98 -0
  735. package/services/history-service/subsquid-multi-chain-history.d.ts +30 -0
  736. package/services/history-service/subsquid-multi-chain-history.js +243 -0
  737. package/services/notification-service/NotificationService.d.ts +3 -0
  738. package/services/notification-service/NotificationService.js +24 -0
  739. package/services/price-service/coingecko.d.ts +2 -0
  740. package/services/price-service/coingecko.js +37 -0
  741. package/services/price-service/index.d.ts +14 -0
  742. package/services/price-service/index.js +57 -0
  743. package/services/request-service/constants.d.ts +1 -0
  744. package/services/request-service/constants.js +4 -0
  745. package/services/request-service/handler/AuthRequestHandler.d.ts +29 -0
  746. package/services/request-service/handler/AuthRequestHandler.js +253 -0
  747. package/services/request-service/handler/EvmRequestHandler.d.ts +19 -0
  748. package/services/request-service/handler/EvmRequestHandler.js +207 -0
  749. package/services/request-service/handler/MetadataRequestHandler.d.ts +18 -0
  750. package/services/request-service/handler/MetadataRequestHandler.js +75 -0
  751. package/services/request-service/handler/PopupHandler.d.ts +10 -0
  752. package/services/request-service/handler/PopupHandler.js +77 -0
  753. package/services/request-service/handler/SubstrateRequestHandler.d.ts +17 -0
  754. package/services/request-service/handler/SubstrateRequestHandler.js +94 -0
  755. package/services/request-service/helper/index.d.ts +2 -0
  756. package/services/request-service/helper/index.js +44 -0
  757. package/services/request-service/index.d.ts +45 -0
  758. package/services/request-service/index.js +151 -0
  759. package/services/request-service/types.d.ts +24 -0
  760. package/services/request-service/types.js +1 -0
  761. package/services/setting-service/SettingService.d.ts +8 -0
  762. package/services/setting-service/SettingService.js +30 -0
  763. package/services/storage-service/DatabaseService.d.ts +64 -0
  764. package/services/storage-service/DatabaseService.js +221 -0
  765. package/services/storage-service/databases/index.d.ts +45 -0
  766. package/services/storage-service/databases/index.js +36 -0
  767. package/services/storage-service/db-stores/Asset.d.ts +6 -0
  768. package/services/storage-service/db-stores/Asset.js +12 -0
  769. package/services/storage-service/db-stores/Balance.d.ts +7 -0
  770. package/services/storage-service/db-stores/Balance.js +49 -0
  771. package/services/storage-service/db-stores/BaseStore.d.ts +11 -0
  772. package/services/storage-service/db-stores/BaseStore.js +22 -0
  773. package/services/storage-service/db-stores/BaseStoreWithAddress.d.ts +5 -0
  774. package/services/storage-service/db-stores/BaseStoreWithAddress.js +20 -0
  775. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +7 -0
  776. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +25 -0
  777. package/services/storage-service/db-stores/BaseStoreWithChain.d.ts +5 -0
  778. package/services/storage-service/db-stores/BaseStoreWithChain.js +12 -0
  779. package/services/storage-service/db-stores/Chain.d.ts +6 -0
  780. package/services/storage-service/db-stores/Chain.js +12 -0
  781. package/services/storage-service/db-stores/ChainStakingMetadata.d.ts +9 -0
  782. package/services/storage-service/db-stores/ChainStakingMetadata.js +29 -0
  783. package/services/storage-service/db-stores/Crowdloan.d.ts +6 -0
  784. package/services/storage-service/db-stores/Crowdloan.js +15 -0
  785. package/services/storage-service/db-stores/Migration.d.ts +4 -0
  786. package/services/storage-service/db-stores/Migration.js +5 -0
  787. package/services/storage-service/db-stores/Nft.d.ts +10 -0
  788. package/services/storage-service/db-stores/Nft.js +58 -0
  789. package/services/storage-service/db-stores/NftCollection.d.ts +7 -0
  790. package/services/storage-service/db-stores/NftCollection.js +22 -0
  791. package/services/storage-service/db-stores/NominatorMetadata.d.ts +9 -0
  792. package/services/storage-service/db-stores/NominatorMetadata.js +22 -0
  793. package/services/storage-service/db-stores/Price.d.ts +4 -0
  794. package/services/storage-service/db-stores/Price.js +5 -0
  795. package/services/storage-service/db-stores/Staking.d.ts +9 -0
  796. package/services/storage-service/db-stores/Staking.js +29 -0
  797. package/services/storage-service/db-stores/Transaction.d.ts +12 -0
  798. package/services/storage-service/db-stores/Transaction.js +41 -0
  799. package/services/storage-service/db-stores/index.d.ts +10 -0
  800. package/services/storage-service/db-stores/index.js +13 -0
  801. package/services/transaction-service/helpers/index.d.ts +5 -0
  802. package/services/transaction-service/helpers/index.js +14 -0
  803. package/services/transaction-service/index.d.ts +39 -0
  804. package/services/transaction-service/index.js +592 -0
  805. package/services/transaction-service/types.d.ts +45 -0
  806. package/services/transaction-service/types.js +1 -0
  807. package/services/transaction-service/utils.d.ts +4 -0
  808. package/services/transaction-service/utils.js +23 -0
  809. package/signers/substrates/KeyringSigner.d.ts +1 -1
  810. package/stores/AccountRef.d.ts +5 -0
  811. package/stores/AccountRef.js +10 -0
  812. package/stores/Accounts.d.ts +1 -1
  813. package/stores/Application.d.ts +7 -0
  814. package/stores/Application.js +20 -0
  815. package/stores/AssetSetting.d.ts +5 -0
  816. package/stores/AssetSetting.js +12 -0
  817. package/stores/Authorize.d.ts +5 -0
  818. package/stores/Authorize.js +10 -0
  819. package/stores/CurrentAccountStore.d.ts +5 -0
  820. package/stores/CurrentAccountStore.js +10 -0
  821. package/stores/Keyring.d.ts +7 -0
  822. package/stores/Keyring.js +32 -0
  823. package/stores/Settings.d.ts +5 -0
  824. package/stores/Settings.js +10 -0
  825. package/stores/SubscribableStore.d.ts +9 -0
  826. package/stores/SubscribableStore.js +25 -0
  827. package/stores/TransactionHistory.d.ts +6 -0
  828. package/stores/TransactionHistory.js +29 -0
  829. package/stores/TransactionHistoryV2.d.ts +5 -0
  830. package/stores/TransactionHistoryV2.js +10 -0
  831. package/stores/TransactionHistoryV3.d.ts +5 -0
  832. package/stores/TransactionHistoryV3.js +10 -0
  833. package/stores/index.d.ts +1 -0
  834. package/stores/index.js +2 -1
  835. package/utils/address.d.ts +1 -0
  836. package/utils/address.js +10 -0
  837. package/utils/eth/mergeTransactionAndSignature.d.ts +2 -0
  838. package/utils/eth/mergeTransactionAndSignature.js +14 -0
  839. package/utils/eth/parseTransaction/base.d.ts +17 -0
  840. package/utils/eth/parseTransaction/base.js +273 -0
  841. package/utils/eth/parseTransaction/index.d.ts +6 -0
  842. package/utils/eth/parseTransaction/index.js +220 -0
  843. package/utils/eth.d.ts +18 -0
  844. package/utils/eth.js +64 -0
  845. package/utils/index.d.ts +36 -0
  846. package/utils/index.js +270 -2
  847. package/utils/keyring.d.ts +4 -0
  848. package/utils/keyring.js +49 -0
  849. package/utils/request.d.ts +1 -0
  850. package/utils/request.js +7 -0
  851. package/errors/SubWalletProviderError.d.ts +0 -6
@@ -0,0 +1,3038 @@
1
+ // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import Common from '@ethereumjs/common';
5
+ import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
6
+ import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/extension-base/background/handlers/Extension';
7
+ import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
8
+ import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
9
+ import { AccountExternalErrorCode, BasicTxErrorType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
10
+ import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
11
+ import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
12
+ import { getFreeBalance, subscribeFreeBalance } from '@subwallet/extension-base/koni/api/dotsama/balance';
13
+ import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
14
+ import { checkReferenceCount, checkSupportTransfer, createTransferExtrinsic } from '@subwallet/extension-base/koni/api/dotsama/transfer';
15
+ import { getNftTransferExtrinsic, isRecipientSelf } from '@subwallet/extension-base/koni/api/nft/transfer';
16
+ import { getBondingExtrinsic, getCancelWithdrawalExtrinsic, getClaimRewardExtrinsic, getNominationPoolsInfo, getUnbondingExtrinsic, getValidatorsInfo, getWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding';
17
+ import { getTuringCancelCompoundingExtrinsic, getTuringCompoundExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/paraChain';
18
+ import { getPoolingBondingExtrinsic, getPoolingUnbondingExtrinsic, getPoolingWithdrawalExtrinsic } from '@subwallet/extension-base/koni/api/staking/bonding/relayChain';
19
+ import { getERC20TransactionObject, getERC721Transaction, getEVMTransactionObject } from '@subwallet/extension-base/koni/api/tokens/evm/transfer';
20
+ import { getPSP34Transaction, getPSP34TransferExtrinsic } from '@subwallet/extension-base/koni/api/tokens/wasm';
21
+ import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
22
+ import { _getChainNativeTokenBasicInfo, _getContractAddressOfToken, _getEvmChainId, _getSubstrateGenesisHash, _getTokenMinAmount, _isAssetSmartContractNft, _isChainEvmCompatible, _isCustomAsset, _isNativeToken, _isTokenEvmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
23
+ import { EXTENSION_REQUEST_URL } from '@subwallet/extension-base/services/request-service/constants';
24
+ import { createTransactionFromRLP, signatureToHex } from '@subwallet/extension-base/utils/eth';
25
+ import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
26
+ import { createPair } from '@subwallet/keyring';
27
+ import { keyring } from '@subwallet/ui-keyring';
28
+ import { accounts as accountsObservable } from '@subwallet/ui-keyring/observable/accounts';
29
+ import BigN from 'bignumber.js';
30
+ import { Transaction } from 'ethereumjs-tx';
31
+ import { TypeRegistry } from '@polkadot/types';
32
+ import { assert, BN, hexStripPrefix, hexToU8a, isAscii, isHex, u8aToHex, u8aToString } from '@polkadot/util';
33
+ import { base64Decode, isEthereumAddress, jsonDecrypt, keyExtractSuri, mnemonicGenerate, mnemonicValidate } from '@polkadot/util-crypto';
34
+ const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
35
+ function getSuri(seed, type) {
36
+ return type === 'ethereum' ? `${seed}${ETH_DERIVE_DEFAULT}` : seed;
37
+ }
38
+ function transformAccounts(accounts) {
39
+ return Object.values(accounts).map(({
40
+ json: {
41
+ address,
42
+ meta
43
+ },
44
+ type
45
+ }) => ({
46
+ address,
47
+ ...meta,
48
+ type
49
+ }));
50
+ }
51
+ const ACCOUNT_ALL_JSON = {
52
+ address: ALL_ACCOUNT_KEY,
53
+ name: 'All'
54
+ };
55
+ export default class KoniExtension {
56
+ #koniState;
57
+ constructor(state) {
58
+ this.#koniState = state;
59
+ }
60
+
61
+ /// Clone from PolkadotJs
62
+ accountsCreateExternal({
63
+ address,
64
+ genesisHash,
65
+ name
66
+ }) {
67
+ keyring.addExternal(address, {
68
+ genesisHash,
69
+ name
70
+ });
71
+ return true;
72
+ }
73
+ accountsCreateHardware({
74
+ accountIndex,
75
+ address,
76
+ addressOffset,
77
+ genesisHash,
78
+ hardwareType,
79
+ name
80
+ }) {
81
+ keyring.addHardware(address, hardwareType, {
82
+ accountIndex,
83
+ addressOffset,
84
+ genesisHash,
85
+ name
86
+ });
87
+ return true;
88
+ }
89
+ accountsCreateSuri({
90
+ genesisHash,
91
+ name,
92
+ suri,
93
+ type
94
+ }) {
95
+ keyring.addUri(getSuri(suri, type), {
96
+ genesisHash,
97
+ name
98
+ }, type);
99
+ return true;
100
+ }
101
+ accountsChangePassword({
102
+ address,
103
+ newPass,
104
+ oldPass
105
+ }) {
106
+ const pair = keyring.getPair(address);
107
+ assert(pair, 'Unable to find pair');
108
+ try {
109
+ if (!pair.isLocked) {
110
+ pair.lock();
111
+ }
112
+ pair.decodePkcs8(oldPass);
113
+ } catch (error) {
114
+ throw new Error('oldPass is invalid');
115
+ }
116
+ keyring.encryptAccount(pair, newPass);
117
+ return true;
118
+ }
119
+ accountsEdit({
120
+ address,
121
+ name
122
+ }) {
123
+ const pair = keyring.getPair(address);
124
+ assert(pair, 'Unable to find pair');
125
+ keyring.saveAccountMeta(pair, {
126
+ ...pair.meta,
127
+ name
128
+ });
129
+ return true;
130
+ }
131
+ accountsExport({
132
+ address,
133
+ password
134
+ }) {
135
+ return {
136
+ exportedJson: keyring.backupAccount(keyring.getPair(address), password)
137
+ };
138
+ }
139
+ accountsShow({
140
+ address,
141
+ isShowing
142
+ }) {
143
+ const pair = keyring.getPair(address);
144
+ assert(pair, 'Unable to find pair');
145
+ keyring.saveAccountMeta(pair, {
146
+ ...pair.meta,
147
+ isHidden: !isShowing
148
+ });
149
+ return true;
150
+ }
151
+ accountsValidate({
152
+ address,
153
+ password
154
+ }) {
155
+ try {
156
+ keyring.backupAccount(keyring.getPair(address), password);
157
+ return true;
158
+ } catch (e) {
159
+ return false;
160
+ }
161
+ }
162
+
163
+ // FIXME This looks very much like what we have in Tabs
164
+ accountsSubscribe(id, port) {
165
+ const cb = createSubscription(id, port);
166
+ const subscription = accountsObservable.subject.subscribe(accounts => cb(transformAccounts(accounts)));
167
+ port.onDisconnect.addListener(() => {
168
+ this.cancelSubscription(id);
169
+ subscription.unsubscribe();
170
+ });
171
+ return true;
172
+ }
173
+ metadataApprove({
174
+ id
175
+ }) {
176
+ const queued = this.#koniState.getMetaRequest(id);
177
+ assert(queued, 'Unable to find request');
178
+ const {
179
+ request,
180
+ resolve
181
+ } = queued;
182
+ this.#koniState.saveMetadata(request);
183
+ resolve(true);
184
+ return true;
185
+ }
186
+ metadataGet(genesisHash) {
187
+ return this.#koniState.knownMetadata.find(result => result.genesisHash === genesisHash) || null;
188
+ }
189
+ metadataList() {
190
+ return this.#koniState.knownMetadata;
191
+ }
192
+ metadataReject({
193
+ id
194
+ }) {
195
+ const queued = this.#koniState.getMetaRequest(id);
196
+ assert(queued, 'Unable to find request');
197
+ const {
198
+ reject
199
+ } = queued;
200
+ reject(new Error('Rejected'));
201
+ return true;
202
+ }
203
+ metadataSubscribe(id, port) {
204
+ const cb = createSubscription(id, port);
205
+ const subscription = this.#koniState.metaSubject.subscribe(requests => cb(requests));
206
+ port.onDisconnect.addListener(() => {
207
+ this.cancelSubscription(id);
208
+ subscription.unsubscribe();
209
+ });
210
+ return true;
211
+ }
212
+ jsonRestore({
213
+ file,
214
+ password
215
+ }) {
216
+ try {
217
+ keyring.restoreAccount(file, password, true);
218
+ } catch (error) {
219
+ throw new Error(error.message);
220
+ }
221
+ }
222
+ batchRestore({
223
+ file,
224
+ password
225
+ }) {
226
+ try {
227
+ keyring.restoreAccounts(file, password);
228
+ } catch (error) {
229
+ throw new Error(error.message);
230
+ }
231
+ }
232
+ jsonGetAccountInfo(json) {
233
+ try {
234
+ const {
235
+ address,
236
+ meta: {
237
+ genesisHash,
238
+ name
239
+ },
240
+ type
241
+ } = keyring.createFromJson(json);
242
+ return {
243
+ address,
244
+ genesisHash,
245
+ name,
246
+ type
247
+ };
248
+ } catch (e) {
249
+ console.error(e);
250
+ throw new Error(e.message);
251
+ }
252
+ }
253
+ seedCreate({
254
+ length = SEED_DEFAULT_LENGTH,
255
+ seed: _seed,
256
+ type
257
+ }) {
258
+ const seed = _seed || mnemonicGenerate(length);
259
+ return {
260
+ address: keyring.createFromUri(getSuri(seed, type), {}, type).address,
261
+ seed
262
+ };
263
+ }
264
+ seedValidate({
265
+ suri,
266
+ type
267
+ }) {
268
+ const {
269
+ phrase
270
+ } = keyExtractSuri(suri);
271
+ if (isHex(phrase)) {
272
+ assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
273
+ } else {
274
+ // sadly isHex detects as string, so we need a cast here
275
+ assert(SEED_LENGTHS.includes(phrase.split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
276
+ assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
277
+ }
278
+ return {
279
+ address: keyring.createFromUri(getSuri(suri, type), {}, type).address,
280
+ suri
281
+ };
282
+ }
283
+ signingApproveSignature({
284
+ id,
285
+ signature
286
+ }) {
287
+ const queued = this.#koniState.getSignRequest(id);
288
+ assert(queued, 'Unable to find request');
289
+ const {
290
+ resolve
291
+ } = queued;
292
+ resolve({
293
+ id,
294
+ signature
295
+ });
296
+ return true;
297
+ }
298
+ signingCancel({
299
+ id
300
+ }) {
301
+ const queued = this.#koniState.getSignRequest(id);
302
+ assert(queued, 'Unable to find request');
303
+ const {
304
+ reject
305
+ } = queued;
306
+ reject(new Error('Cancelled'));
307
+ return true;
308
+ }
309
+
310
+ // FIXME This looks very much like what we have in authorization
311
+ signingSubscribe(id, port) {
312
+ const cb = createSubscription(id, port);
313
+ const subscription = this.#koniState.signSubject.subscribe(requests => cb(requests));
314
+ port.onDisconnect.addListener(() => {
315
+ this.cancelSubscription(id);
316
+ subscription.unsubscribe();
317
+ });
318
+ return true;
319
+ }
320
+ windowOpen(path) {
321
+ const url = `${chrome.extension.getURL('index.html')}#${path}`;
322
+ if (!ALLOWED_PATH.includes(path)) {
323
+ console.error('Not allowed to open the url:', url);
324
+ return false;
325
+ }
326
+ withErrorLog(() => chrome.tabs.create({
327
+ url
328
+ }));
329
+ return true;
330
+ }
331
+ derive(parentAddress, suri, password, metadata) {
332
+ const parentPair = keyring.getPair(parentAddress);
333
+ try {
334
+ parentPair.decodePkcs8(password);
335
+ } catch (e) {
336
+ throw new Error('invalid password');
337
+ }
338
+ try {
339
+ return parentPair.derive(suri, metadata);
340
+ } catch (err) {
341
+ throw new Error(`"${suri}" is not a valid derivation path`);
342
+ }
343
+ }
344
+ derivationValidate({
345
+ parentAddress,
346
+ parentPassword,
347
+ suri
348
+ }) {
349
+ const childPair = this.derive(parentAddress, suri, parentPassword, {});
350
+ return {
351
+ address: childPair.address,
352
+ suri
353
+ };
354
+ }
355
+ derivationCreate({
356
+ genesisHash,
357
+ name,
358
+ parentAddress,
359
+ parentPassword,
360
+ suri
361
+ }) {
362
+ const childPair = this.derive(parentAddress, suri, parentPassword, {
363
+ genesisHash,
364
+ name,
365
+ parentAddress,
366
+ suri
367
+ });
368
+ keyring.addPair(childPair, true);
369
+ return true;
370
+ }
371
+
372
+ ///
373
+
374
+ cancelSubscription(id) {
375
+ return this.#koniState.cancelSubscription(id);
376
+ }
377
+ createUnsubscriptionHandle(id, unsubscribe) {
378
+ this.#koniState.createUnsubscriptionHandle(id, unsubscribe);
379
+ }
380
+ decodeAddress = (key, ignoreChecksum, ss58Format) => {
381
+ return keyring.decodeAddress(key, ignoreChecksum, ss58Format);
382
+ };
383
+ encodeAddress = (key, ss58Format) => {
384
+ return keyring.encodeAddress(key, ss58Format);
385
+ };
386
+ accountExportPrivateKey({
387
+ address,
388
+ password
389
+ }) {
390
+ return this.#koniState.accountExportPrivateKey({
391
+ address,
392
+ password
393
+ });
394
+ }
395
+ checkPublicAndSecretKey(request) {
396
+ return this.#koniState.checkPublicAndSecretKey(request);
397
+ }
398
+ async accountsGetAllWithCurrentAddress(id, port) {
399
+ const cb = createSubscription(id, port);
400
+ return await new Promise(resolve => {
401
+ const subscription = accountsObservable.subject.subscribe(storedAccounts => {
402
+ const transformedAccounts = transformAccounts(storedAccounts);
403
+ const accounts = transformedAccounts && transformedAccounts.length ? [{
404
+ ...ACCOUNT_ALL_JSON
405
+ }, ...transformedAccounts] : [];
406
+ const accountsWithCurrentAddress = {
407
+ accounts
408
+ };
409
+ setTimeout(() => {
410
+ this.#koniState.getCurrentAccount(accountInfo => {
411
+ if (accountInfo) {
412
+ accountsWithCurrentAddress.currentAddress = accountInfo.address;
413
+ if (accountInfo.address === ALL_ACCOUNT_KEY) {
414
+ accountsWithCurrentAddress.currentGenesisHash = accountInfo.currentGenesisHash;
415
+ } else {
416
+ const acc = accounts.find(a => a.address === accountInfo.address);
417
+ accountsWithCurrentAddress.currentGenesisHash = (acc === null || acc === void 0 ? void 0 : acc.genesisHash) || ALL_GENESIS_HASH;
418
+ }
419
+ }
420
+ resolve(accountsWithCurrentAddress);
421
+ cb(accountsWithCurrentAddress);
422
+ });
423
+ }, 300);
424
+ });
425
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
426
+ port.onDisconnect.addListener(() => {
427
+ this.cancelSubscription(id);
428
+ });
429
+ });
430
+ }
431
+ accountsGetAll(id, port) {
432
+ const cb = createSubscription(id, port);
433
+ const subscription = keyring.keyringOption.optionsSubject.subscribe(options => {
434
+ const optionsInputAddress = {
435
+ options
436
+ };
437
+ cb(optionsInputAddress);
438
+ });
439
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
440
+ port.onDisconnect.addListener(() => {
441
+ this.cancelSubscription(id);
442
+ });
443
+ return id;
444
+ }
445
+ saveRecentAccountId({
446
+ accountId
447
+ }) {
448
+ return keyring.saveRecent(accountId);
449
+ }
450
+ triggerAccountsSubscription() {
451
+ const accountsSubject = accountsObservable.subject;
452
+ accountsSubject.next(accountsSubject.getValue());
453
+ return true;
454
+ }
455
+ _getAuthListV2() {
456
+ return new Promise((resolve, reject) => {
457
+ this.#koniState.getAuthorize(rs => {
458
+ const accounts = accountsObservable.subject.getValue();
459
+ const addressList = Object.keys(accounts);
460
+ const urlList = Object.keys(rs);
461
+ if (Object.keys(rs[urlList[0]].isAllowedMap).toString() !== addressList.toString()) {
462
+ urlList.forEach(url => {
463
+ addressList.forEach(address => {
464
+ if (!Object.keys(rs[url].isAllowedMap).includes(address)) {
465
+ rs[url].isAllowedMap[address] = false;
466
+ }
467
+ });
468
+ Object.keys(rs[url].isAllowedMap).forEach(address => {
469
+ if (!addressList.includes(address)) {
470
+ delete rs[url].isAllowedMap[address];
471
+ }
472
+ });
473
+ });
474
+ this.#koniState.setAuthorize(rs);
475
+ }
476
+ resolve(rs);
477
+ });
478
+ });
479
+ }
480
+ authorizeSubscribeV2(id, port) {
481
+ const cb = createSubscription(id, port);
482
+ const subscription = this.#koniState.authSubjectV2.subscribe(requests => cb(requests));
483
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
484
+ port.onDisconnect.addListener(() => {
485
+ this.cancelSubscription(id);
486
+ });
487
+ return true;
488
+ }
489
+ async getAuthListV2() {
490
+ const authList = await this._getAuthListV2();
491
+ return {
492
+ list: authList
493
+ };
494
+ }
495
+ authorizeApproveV2({
496
+ accounts,
497
+ id
498
+ }) {
499
+ const queued = this.#koniState.getAuthRequestV2(id);
500
+ assert(queued, 'Unable to find request');
501
+ const {
502
+ resolve
503
+ } = queued;
504
+ resolve({
505
+ accounts,
506
+ result: true
507
+ });
508
+ return true;
509
+ }
510
+ authorizeRejectV2({
511
+ id
512
+ }) {
513
+ const queued = this.#koniState.getAuthRequestV2(id);
514
+ assert(queued, 'Unable to find request');
515
+ const {
516
+ reject
517
+ } = queued;
518
+ reject(new Error('Rejected'));
519
+ return true;
520
+ }
521
+ authorizeCancelV2({
522
+ id
523
+ }) {
524
+ const queued = this.#koniState.getAuthRequestV2(id);
525
+ assert(queued, 'Unable to find request');
526
+ const {
527
+ reject
528
+ } = queued;
529
+
530
+ // Reject without error meaning cancel
531
+ reject(new Error('Cancelled'));
532
+ return true;
533
+ }
534
+ _forgetSite(url, callBack) {
535
+ this.#koniState.getAuthorize(value => {
536
+ assert(value, 'The source is not known');
537
+ delete value[url];
538
+ this.#koniState.setAuthorize(value, () => {
539
+ callBack && callBack(value);
540
+ });
541
+ });
542
+ }
543
+ forgetSite(data, id, port) {
544
+ const cb = createSubscription(id, port);
545
+ this._forgetSite(data.url, items => {
546
+ cb(items);
547
+ });
548
+ port.onDisconnect.addListener(() => {
549
+ this.cancelSubscription(id);
550
+ });
551
+ return true;
552
+ }
553
+ _forgetAllSite(callBack) {
554
+ this.#koniState.getAuthorize(value => {
555
+ assert(value, 'The source is not known');
556
+ value = {};
557
+ this.#koniState.setAuthorize(value, () => {
558
+ callBack && callBack(value);
559
+ });
560
+ });
561
+ }
562
+ forgetAllSite(id, port) {
563
+ const cb = createSubscription(id, port);
564
+ this._forgetAllSite(items => {
565
+ cb(items);
566
+ });
567
+ port.onDisconnect.addListener(() => {
568
+ this.cancelSubscription(id);
569
+ });
570
+ return true;
571
+ }
572
+ getNonReadonlyAccounts() {
573
+ const storedAccounts = accountsObservable.subject.getValue();
574
+ const transformedAccounts = transformAccounts(storedAccounts);
575
+ return transformedAccounts.filter(a => !a.isReadOnly).map(a => a.address);
576
+ }
577
+ filterAccountsByAccountAuthType(accounts, accountAuthType) {
578
+ if (accountAuthType === 'substrate') {
579
+ return accounts.filter(address => !isEthereumAddress(address));
580
+ } else if (accountAuthType === 'evm') {
581
+ return accounts.filter(address => isEthereumAddress(address));
582
+ } else {
583
+ return accounts;
584
+ }
585
+ }
586
+ _changeAuthorizationAll(connectValue, callBack) {
587
+ this.#koniState.getAuthorize(value => {
588
+ assert(value, 'The source is not known');
589
+ const nonReadonlyAccounts = this.getNonReadonlyAccounts();
590
+ Object.keys(value).forEach(url => {
591
+ const targetAccounts = this.filterAccountsByAccountAuthType(nonReadonlyAccounts, value[url].accountAuthType);
592
+ targetAccounts.forEach(address => {
593
+ value[url].isAllowedMap[address] = connectValue;
594
+ });
595
+ });
596
+ this.#koniState.setAuthorize(value, () => {
597
+ callBack && callBack(value);
598
+ });
599
+ });
600
+ }
601
+ changeAuthorizationAll(data, id, port) {
602
+ const cb = createSubscription(id, port);
603
+ this._changeAuthorizationAll(data.connectValue, items => {
604
+ cb(items);
605
+ });
606
+ port.onDisconnect.addListener(() => {
607
+ this.cancelSubscription(id);
608
+ });
609
+ return true;
610
+ }
611
+ _changeAuthorization(url, connectValue, callBack) {
612
+ this.#koniState.getAuthorize(value => {
613
+ assert(value[url], 'The source is not known');
614
+ const nonReadonlyAccounts = this.getNonReadonlyAccounts();
615
+ const targetAccounts = this.filterAccountsByAccountAuthType(nonReadonlyAccounts, value[url].accountAuthType);
616
+ targetAccounts.forEach(address => {
617
+ value[url].isAllowedMap[address] = connectValue;
618
+ });
619
+ this.#koniState.setAuthorize(value, () => {
620
+ callBack && callBack(value);
621
+ });
622
+ });
623
+ }
624
+ toggleAuthorization2(url) {
625
+ return new Promise(resolve => {
626
+ this.#koniState.getAuthorize(value => {
627
+ assert(value[url], 'The source is not known');
628
+ value[url].isAllowed = !value[url].isAllowed;
629
+ this.#koniState.setAuthorize(value, () => {
630
+ resolve({
631
+ list: value
632
+ });
633
+ });
634
+ });
635
+ });
636
+ }
637
+ changeAuthorization(data, id, port) {
638
+ const cb = createSubscription(id, port);
639
+ this._changeAuthorization(data.url, data.connectValue, items => {
640
+ cb(items);
641
+ });
642
+ port.onDisconnect.addListener(() => {
643
+ this.cancelSubscription(id);
644
+ });
645
+ return true;
646
+ }
647
+ _changeAuthorizationPerAcc(address, connectValue, url, callBack) {
648
+ this.#koniState.getAuthorize(value => {
649
+ assert(value, 'The source is not known');
650
+ value[url].isAllowedMap[address] = connectValue;
651
+ console.log('Devbu: ', value);
652
+ this.#koniState.setAuthorize(value, () => {
653
+ callBack && callBack(value);
654
+ });
655
+ });
656
+ }
657
+ _changeAuthorizationBlock(connectValue, id) {
658
+ this.#koniState.getAuthorize(value => {
659
+ assert(value, 'The source is not known');
660
+ value[id].isAllowed = connectValue;
661
+ console.log('Devbu: ', value);
662
+ this.#koniState.setAuthorize(value);
663
+ });
664
+ }
665
+ _changeAuthorizationPerSite(values, id) {
666
+ this.#koniState.getAuthorize(value => {
667
+ assert(value, 'The source is not known');
668
+ value[id].isAllowedMap = values;
669
+ console.log('Devbu: ', value);
670
+ this.#koniState.setAuthorize(value);
671
+ });
672
+ }
673
+ changeAuthorizationPerAcc(data, id, port) {
674
+ const cb = createSubscription(id, port);
675
+ this._changeAuthorizationPerAcc(data.address, data.connectValue, data.url, items => {
676
+ cb(items);
677
+ });
678
+ port.onDisconnect.addListener(() => {
679
+ this.cancelSubscription(id);
680
+ });
681
+ return true;
682
+ }
683
+ changeAuthorizationPerSite(data) {
684
+ this._changeAuthorizationPerSite(data.values, data.id);
685
+ return true;
686
+ }
687
+ changeAuthorizationBlock(data) {
688
+ this._changeAuthorizationBlock(data.connectedValue, data.id);
689
+ return true;
690
+ }
691
+ async getSettings() {
692
+ return await new Promise(resolve => {
693
+ this.#koniState.getSettings(value => {
694
+ resolve(value);
695
+ });
696
+ });
697
+ }
698
+ toggleBalancesVisibility(id, port) {
699
+ const cb = createSubscription(id, port);
700
+ this.#koniState.getSettings(value => {
701
+ const updateValue = {
702
+ ...value,
703
+ isShowBalance: !value.isShowBalance
704
+ };
705
+ this.#koniState.setSettings(updateValue, () => {
706
+ // eslint-disable-next-line node/no-callback-literal
707
+ cb(updateValue);
708
+ });
709
+ });
710
+ port.onDisconnect.addListener(() => {
711
+ this.cancelSubscription(id);
712
+ });
713
+ return true;
714
+ }
715
+ saveAccountAllLogo(data, id, port) {
716
+ const cb = createSubscription(id, port);
717
+ this.#koniState.getSettings(value => {
718
+ const updateValue = {
719
+ ...value,
720
+ accountAllLogo: data
721
+ };
722
+ this.#koniState.setSettings(updateValue, () => {
723
+ // eslint-disable-next-line node/no-callback-literal
724
+ cb(updateValue);
725
+ });
726
+ });
727
+ port.onDisconnect.addListener(() => {
728
+ this.cancelSubscription(id);
729
+ });
730
+ return true;
731
+ }
732
+ saveTheme(data, id, port) {
733
+ const cb = createSubscription(id, port);
734
+ this.#koniState.setTheme(data, cb);
735
+ port.onDisconnect.addListener(() => {
736
+ this.cancelSubscription(id);
737
+ });
738
+ return true;
739
+ }
740
+ saveBrowserConfirmationType(data, id, port) {
741
+ const cb = createSubscription(id, port);
742
+ this.#koniState.setBrowserConfirmationType(data, cb);
743
+ port.onDisconnect.addListener(() => {
744
+ this.cancelSubscription(id);
745
+ });
746
+ return true;
747
+ }
748
+ async subscribeSettings(id, port) {
749
+ const cb = createSubscription(id, port);
750
+ const balancesVisibilitySubscription = this.#koniState.subscribeSettingsSubject().subscribe({
751
+ next: rs => {
752
+ cb(rs);
753
+ }
754
+ });
755
+ this.createUnsubscriptionHandle(id, balancesVisibilitySubscription.unsubscribe);
756
+ port.onDisconnect.addListener(() => {
757
+ this.cancelSubscription(id);
758
+ });
759
+ return await this.getSettings();
760
+ }
761
+ async subscribeAuthUrls(id, port) {
762
+ const cb = createSubscription(id, port);
763
+ const authorizeUrlSubscription = this.#koniState.subscribeAuthorizeUrlSubject().subscribe({
764
+ next: rs => {
765
+ cb(rs);
766
+ }
767
+ });
768
+ this.createUnsubscriptionHandle(id, authorizeUrlSubscription.unsubscribe);
769
+ port.onDisconnect.addListener(() => {
770
+ this.cancelSubscription(id);
771
+ });
772
+ return await this.#koniState.getAuthList();
773
+ }
774
+ _saveCurrentAccountAddress(address, callback) {
775
+ this.#koniState.getCurrentAccount(accountInfo => {
776
+ if (!accountInfo) {
777
+ accountInfo = {
778
+ address,
779
+ currentGenesisHash: ALL_GENESIS_HASH,
780
+ allGenesisHash: ALL_GENESIS_HASH || undefined
781
+ };
782
+ } else {
783
+ accountInfo.address = address;
784
+ if (address !== ALL_ACCOUNT_KEY) {
785
+ const currentKeyPair = keyring.getAccount(address);
786
+ accountInfo.currentGenesisHash = (currentKeyPair === null || currentKeyPair === void 0 ? void 0 : currentKeyPair.meta.genesisHash) || ALL_GENESIS_HASH;
787
+ } else {
788
+ accountInfo.currentGenesisHash = accountInfo.allGenesisHash || ALL_GENESIS_HASH;
789
+ }
790
+ }
791
+ this.#koniState.setCurrentAccount(accountInfo, () => {
792
+ callback && callback(accountInfo);
793
+ });
794
+ });
795
+ }
796
+ updateCurrentAccountAddress(address) {
797
+ this._saveCurrentAccountAddress(address, () => {
798
+ this.triggerAccountsSubscription();
799
+ });
800
+ return true;
801
+ }
802
+ saveCurrentAccountAddress(data, id, port) {
803
+ const cb = createSubscription(id, port);
804
+ this._saveCurrentAccountAddress(data.address, cb);
805
+ port.onDisconnect.addListener(() => {
806
+ this.cancelSubscription(id);
807
+ });
808
+ return true;
809
+ }
810
+ getAssetSetting() {
811
+ return new Promise((resolve, reject) => {
812
+ this.#koniState.getAssetSettings(rs => {
813
+ resolve(rs);
814
+ });
815
+ });
816
+ }
817
+ subscribeAssetSetting(id, port) {
818
+ const cb = createSubscription(id, port);
819
+ const assetSettingSubscription = this.#koniState.subscribeAssetSettings().subscribe({
820
+ next: rs => {
821
+ cb(rs);
822
+ }
823
+ });
824
+ this.createUnsubscriptionHandle(id, assetSettingSubscription.unsubscribe);
825
+ port.onDisconnect.addListener(() => {
826
+ this.cancelSubscription(id);
827
+ });
828
+ return this.getAssetSetting();
829
+ }
830
+ updateAssetSetting(params) {
831
+ try {
832
+ this.#koniState.updateAssetSetting(params.tokenSlug, params.assetSetting);
833
+ return true;
834
+ } catch (e) {
835
+ console.error('Error updating asset setting', e);
836
+ return false;
837
+ }
838
+ }
839
+ async getPrice() {
840
+ return this.#koniState.priceService.getPrice();
841
+ }
842
+ subscribePrice(id, port) {
843
+ const cb = createSubscription(id, port);
844
+ const priceSubscription = this.#koniState.priceService.getPriceSubject().subscribe(rs => {
845
+ cb(rs);
846
+ });
847
+ this.createUnsubscriptionHandle(id, priceSubscription.unsubscribe);
848
+ port.onDisconnect.addListener(() => {
849
+ this.cancelSubscription(id);
850
+ });
851
+ return this.getPrice();
852
+ }
853
+ getBalance(reset) {
854
+ return this.#koniState.getBalance(reset);
855
+ }
856
+ subscribeBalance(id, port) {
857
+ const cb = createSubscription(id, port);
858
+ const balanceSubscription = this.#koniState.subscribeBalance().subscribe({
859
+ next: rs => {
860
+ cb(rs);
861
+ }
862
+ });
863
+ this.createUnsubscriptionHandle(id, balanceSubscription.unsubscribe);
864
+ port.onDisconnect.addListener(() => {
865
+ this.cancelSubscription(id);
866
+ });
867
+ return this.getBalance(true);
868
+ }
869
+ getCrowdloan(reset) {
870
+ return this.#koniState.getCrowdloan(reset);
871
+ }
872
+ subscribeCrowdloan(id, port) {
873
+ const cb = createSubscription(id, port);
874
+ const crowdloanSubscription = this.#koniState.subscribeCrowdloan().subscribe({
875
+ next: rs => {
876
+ cb(rs);
877
+ }
878
+ });
879
+ this.createUnsubscriptionHandle(id, crowdloanSubscription.unsubscribe);
880
+ port.onDisconnect.addListener(() => {
881
+ this.cancelSubscription(id);
882
+ });
883
+ return this.getCrowdloan(true);
884
+ }
885
+ validatePassword(json, password) {
886
+ const cryptoType = Array.isArray(json.encoding.content) ? json.encoding.content[1] : 'ed25519';
887
+ const encType = Array.isArray(json.encoding.type) ? json.encoding.type : [json.encoding.type];
888
+ const pair = createPair({
889
+ toSS58: this.encodeAddress,
890
+ type: cryptoType
891
+ }, {
892
+ publicKey: this.decodeAddress(json.address, true)
893
+ }, json.meta, isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded), encType);
894
+
895
+ // unlock then lock (locking cleans secretKey, so needs to be last)
896
+ try {
897
+ pair.decodePkcs8(password);
898
+ pair.lock();
899
+ return true;
900
+ } catch (e) {
901
+ console.error(e);
902
+ return false;
903
+ }
904
+ }
905
+ validatedAccountsPassword(json, password) {
906
+ try {
907
+ u8aToString(jsonDecrypt(json, password));
908
+ return true;
909
+ } catch (e) {
910
+ return false;
911
+ }
912
+ }
913
+ _addAddressToAuthList(address, isAllowed) {
914
+ this.#koniState.getAuthorize(value => {
915
+ if (value && Object.keys(value).length) {
916
+ Object.keys(value).forEach(url => {
917
+ value[url].isAllowedMap[address] = isAllowed;
918
+ });
919
+ this.#koniState.setAuthorize(value);
920
+ }
921
+ });
922
+ }
923
+ _addAddressesToAuthList(addresses, isAllowed) {
924
+ this.#koniState.getAuthorize(value => {
925
+ if (value && Object.keys(value).length) {
926
+ Object.keys(value).forEach(url => {
927
+ addresses.forEach(address => {
928
+ value[url].isAllowedMap[address] = isAllowed;
929
+ });
930
+ }); /**/
931
+
932
+ this.#koniState.setAuthorize(value);
933
+ }
934
+ });
935
+ }
936
+ async accountsCreateSuriV2({
937
+ genesisHash,
938
+ isAllowed,
939
+ name,
940
+ password,
941
+ suri: _suri,
942
+ types
943
+ }) {
944
+ const addressDict = {};
945
+ let changedAccount = false;
946
+ const hasMasterPassword = keyring.keyring.hasMasterPassword;
947
+ if (!hasMasterPassword) {
948
+ if (!password) {
949
+ throw Error('Require password to set up master password');
950
+ } else {
951
+ keyring.changeMasterPassword(password);
952
+ this.#koniState.setKeyringState({
953
+ hasMasterPassword: true,
954
+ isLocked: false,
955
+ isReady: true
956
+ });
957
+ }
958
+ }
959
+ const currentAccount = await new Promise(resolve => {
960
+ this.#koniState.getCurrentAccount(resolve);
961
+ });
962
+ const allGenesisHash = (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.allGenesisHash) || undefined;
963
+ types === null || types === void 0 ? void 0 : types.forEach(type => {
964
+ const suri = getSuri(_suri, type);
965
+ const address = keyring.createFromUri(suri, {}, type).address;
966
+ addressDict[type] = address;
967
+ const newAccountName = type === 'ethereum' ? `${name} - EVM` : name;
968
+ keyring.addUri(suri, {
969
+ genesisHash,
970
+ name: newAccountName
971
+ }, type);
972
+ this._addAddressToAuthList(address, isAllowed);
973
+ if (!changedAccount) {
974
+ if (types.length === 1) {
975
+ this.#koniState.setCurrentAccount({
976
+ address,
977
+ currentGenesisHash: genesisHash || null,
978
+ allGenesisHash
979
+ });
980
+ } else {
981
+ this.#koniState.setCurrentAccount({
982
+ address: ALL_ACCOUNT_KEY,
983
+ currentGenesisHash: allGenesisHash || null,
984
+ allGenesisHash
985
+ });
986
+ }
987
+ changedAccount = true;
988
+ }
989
+ });
990
+ await new Promise(resolve => {
991
+ this.#koniState.addAccountRef(Object.values(addressDict), () => {
992
+ resolve();
993
+ });
994
+ });
995
+ return addressDict;
996
+ }
997
+ async accountsForgetOverride({
998
+ address
999
+ }) {
1000
+ keyring.forgetAccount(address);
1001
+ await new Promise(resolve => {
1002
+ this.#koniState.removeAccountRef(address, () => {
1003
+ resolve();
1004
+ });
1005
+ });
1006
+ await new Promise(resolve => {
1007
+ this.#koniState.getAuthorize(value => {
1008
+ if (value && Object.keys(value).length) {
1009
+ Object.keys(value).forEach(url => {
1010
+ delete value[url].isAllowedMap[address];
1011
+ });
1012
+ this.#koniState.setAuthorize(value, resolve);
1013
+ } else {
1014
+ resolve();
1015
+ }
1016
+ });
1017
+ });
1018
+
1019
+ // Set current account to all account
1020
+ await new Promise(resolve => {
1021
+ this.#koniState.getCurrentAccount(({
1022
+ allGenesisHash
1023
+ }) => {
1024
+ this.#koniState.setCurrentAccount({
1025
+ currentGenesisHash: allGenesisHash || null,
1026
+ address: ALL_ACCOUNT_KEY
1027
+ }, resolve);
1028
+ });
1029
+ });
1030
+ return true;
1031
+ }
1032
+ seedCreateV2({
1033
+ length = SEED_DEFAULT_LENGTH,
1034
+ seed: _seed,
1035
+ types
1036
+ }) {
1037
+ const seed = _seed || mnemonicGenerate(length);
1038
+ const rs = {
1039
+ seed: seed,
1040
+ addressMap: {}
1041
+ };
1042
+ types === null || types === void 0 ? void 0 : types.forEach(type => {
1043
+ rs.addressMap[type] = keyring.createFromUri(getSuri(seed, type), {}, type).address;
1044
+ });
1045
+ return rs;
1046
+ }
1047
+ seedValidateV2({
1048
+ suri,
1049
+ types
1050
+ }) {
1051
+ const {
1052
+ phrase
1053
+ } = keyExtractSuri(suri);
1054
+ if (isHex(phrase)) {
1055
+ assert(isHex(phrase, 256), 'Hex seed needs to be 256-bits');
1056
+ } else {
1057
+ // sadly isHex detects as string, so we need a cast here
1058
+ assert(SEED_LENGTHS.includes(phrase.split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
1059
+ assert(mnemonicValidate(phrase), 'Not a valid mnemonic seed');
1060
+ }
1061
+ const rs = {
1062
+ seed: suri,
1063
+ addressMap: {}
1064
+ };
1065
+ types && types.forEach(type => {
1066
+ rs.addressMap[type] = keyring.createFromUri(getSuri(suri, type), {}, type).address;
1067
+ });
1068
+ return rs;
1069
+ }
1070
+ _checkValidatePrivateKey({
1071
+ suri,
1072
+ types
1073
+ }, autoAddPrefix = false) {
1074
+ const {
1075
+ phrase
1076
+ } = keyExtractSuri(suri);
1077
+ const rs = {
1078
+ autoAddPrefix: autoAddPrefix,
1079
+ addressMap: {}
1080
+ };
1081
+ types && types.forEach(type => {
1082
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1083
+ rs.addressMap[type] = '';
1084
+ });
1085
+ if (isHex(phrase) && isHex(phrase, 256)) {
1086
+ types && types.forEach(type => {
1087
+ rs.addressMap[type] = keyring.createFromUri(getSuri(suri, type), {}, type).address;
1088
+ });
1089
+ } else {
1090
+ rs.autoAddPrefix = false;
1091
+ assert(false, 'Not valid private key');
1092
+ }
1093
+ return rs;
1094
+ }
1095
+ metamaskPrivateKeyValidateV2({
1096
+ suri,
1097
+ types
1098
+ }) {
1099
+ const isValidSuri = suri.startsWith('0x');
1100
+ if (isValidSuri) {
1101
+ return this._checkValidatePrivateKey({
1102
+ suri,
1103
+ types
1104
+ });
1105
+ } else {
1106
+ return this._checkValidatePrivateKey({
1107
+ suri: `0x${suri}`,
1108
+ types
1109
+ }, true);
1110
+ }
1111
+ }
1112
+ deriveV2(parentAddress, suri, metadata) {
1113
+ const parentPair = keyring.getPair(parentAddress);
1114
+ if (parentPair.isLocked) {
1115
+ keyring.unlockPair(parentPair.address);
1116
+ }
1117
+ try {
1118
+ return parentPair.derive(suri, metadata);
1119
+ } catch (err) {
1120
+ throw new Error(`"${suri}" is not a valid derivation path`);
1121
+ }
1122
+ }
1123
+ derivationCreateV2({
1124
+ genesisHash,
1125
+ isAllowed,
1126
+ name,
1127
+ parentAddress,
1128
+ suri
1129
+ }) {
1130
+ const childPair = this.deriveV2(parentAddress, suri, {
1131
+ genesisHash,
1132
+ name,
1133
+ parentAddress,
1134
+ suri
1135
+ });
1136
+ const address = childPair.address;
1137
+ this._saveCurrentAccountAddress(address, () => {
1138
+ keyring.addPair(childPair, true);
1139
+ this._addAddressToAuthList(address, isAllowed);
1140
+ });
1141
+ return true;
1142
+ }
1143
+ jsonRestoreV2({
1144
+ address,
1145
+ file,
1146
+ isAllowed,
1147
+ password,
1148
+ withMasterPassword
1149
+ }) {
1150
+ const isPasswordValidated = this.validatePassword(file, password);
1151
+ if (isPasswordValidated) {
1152
+ try {
1153
+ this._saveCurrentAccountAddress(address, () => {
1154
+ keyring.restoreAccount(file, password, withMasterPassword);
1155
+ this._addAddressToAuthList(address, isAllowed);
1156
+ });
1157
+ } catch (error) {
1158
+ throw new Error(error.message);
1159
+ }
1160
+ } else {
1161
+ throw new Error('Unable to decode using the supplied passphrase');
1162
+ }
1163
+ }
1164
+ batchRestoreV2({
1165
+ accountsInfo,
1166
+ file,
1167
+ isAllowed,
1168
+ password
1169
+ }) {
1170
+ const addressList = accountsInfo.map(acc => acc.address);
1171
+ const isPasswordValidated = this.validatedAccountsPassword(file, password);
1172
+ if (isPasswordValidated) {
1173
+ try {
1174
+ this._saveCurrentAccountAddress(addressList[0], () => {
1175
+ keyring.restoreAccounts(file, password);
1176
+ this._addAddressesToAuthList(addressList, isAllowed);
1177
+ });
1178
+ } catch (error) {
1179
+ throw new Error(error.message);
1180
+ }
1181
+ } else {
1182
+ throw new Error('Unable to decode using the supplied passphrase');
1183
+ }
1184
+ }
1185
+ getNftTransfer() {
1186
+ return new Promise((resolve, reject) => {
1187
+ this.#koniState.getNftTransferSubscription(rs => {
1188
+ resolve(rs);
1189
+ });
1190
+ });
1191
+ }
1192
+ async subscribeNftTransfer(id, port) {
1193
+ const cb = createSubscription(id, port);
1194
+ const nftTransferSubscription = this.#koniState.subscribeNftTransfer().subscribe({
1195
+ next: rs => {
1196
+ cb(rs);
1197
+ }
1198
+ });
1199
+ this.createUnsubscriptionHandle(id, nftTransferSubscription.unsubscribe);
1200
+ port.onDisconnect.addListener(() => {
1201
+ this.cancelSubscription(id);
1202
+ });
1203
+ return this.getNftTransfer();
1204
+ }
1205
+ getNftCollection() {
1206
+ return this.#koniState.getNftCollection();
1207
+ }
1208
+ subscribeNftCollection(id, port) {
1209
+ const cb = createSubscription(id, port);
1210
+ const nftCollectionSubscription = this.#koniState.subscribeNftCollection().subscribe({
1211
+ next: rs => {
1212
+ cb(rs);
1213
+ }
1214
+ });
1215
+ this.createUnsubscriptionHandle(id, nftCollectionSubscription.unsubscribe);
1216
+ port.onDisconnect.addListener(() => {
1217
+ this.cancelSubscription(id);
1218
+ });
1219
+ return this.getNftCollection();
1220
+ }
1221
+ getNft() {
1222
+ return this.#koniState.getNft();
1223
+ }
1224
+ async subscribeNft(id, port) {
1225
+ const cb = createSubscription(id, port);
1226
+ const nftSubscription = this.#koniState.subscribeNft().subscribe({
1227
+ next: rs => {
1228
+ cb(rs);
1229
+ }
1230
+ });
1231
+ this.createUnsubscriptionHandle(id, nftSubscription.unsubscribe);
1232
+ port.onDisconnect.addListener(() => {
1233
+ this.cancelSubscription(id);
1234
+ });
1235
+ return this.getNft();
1236
+ }
1237
+ getStakingReward() {
1238
+ return new Promise((resolve, reject) => {
1239
+ this.#koniState.getStakingReward(rs => {
1240
+ resolve(rs);
1241
+ });
1242
+ });
1243
+ }
1244
+ subscribeStakingReward(id, port) {
1245
+ const cb = createSubscription(id, port);
1246
+ const stakingRewardSubscription = this.#koniState.subscribeStakingReward().subscribe({
1247
+ next: rs => {
1248
+ cb(rs);
1249
+ }
1250
+ });
1251
+ this.createUnsubscriptionHandle(id, stakingRewardSubscription.unsubscribe);
1252
+ port.onDisconnect.addListener(() => {
1253
+ this.cancelSubscription(id);
1254
+ });
1255
+ return this.getStakingReward();
1256
+ }
1257
+ async getStaking() {
1258
+ return this.#koniState.getStaking();
1259
+ }
1260
+ async subscribeStaking(id, port) {
1261
+ const cb = createSubscription(id, port);
1262
+ const stakingSubscription = this.#koniState.subscribeStaking().subscribe({
1263
+ next: rs => {
1264
+ cb(rs);
1265
+ }
1266
+ });
1267
+ this.createUnsubscriptionHandle(id, stakingSubscription.unsubscribe);
1268
+ port.onDisconnect.addListener(() => {
1269
+ this.cancelSubscription(id);
1270
+ });
1271
+ return await this.getStaking();
1272
+ }
1273
+ async subscribeHistory(id, port) {
1274
+ const cb = createSubscription(id, port);
1275
+ const historySubject = await this.#koniState.historyService.getHistorySubject();
1276
+ historySubject.subscribe(cb);
1277
+ this.createUnsubscriptionHandle(id, historySubject.unsubscribe);
1278
+ port.onDisconnect.addListener(() => {
1279
+ this.cancelSubscription(id);
1280
+ });
1281
+ return historySubject.getValue();
1282
+ }
1283
+ setNftTransfer(request) {
1284
+ this.#koniState.setNftTransfer(request);
1285
+ return true;
1286
+ }
1287
+ forceUpdateNftState(request) {
1288
+ if (!request.isSendingSelf) {
1289
+ this.#koniState.removeNfts(request.chain, request.senderAddress, request.collectionId, [request.nft.id || '']).catch(e => console.warn(e));
1290
+ this.isInWalletAccount(request.recipientAddress).then(res => {
1291
+ if (res) {
1292
+ this.#koniState.updateNftData(request.chain, request.nft, request.recipientAddress);
1293
+ }
1294
+ }).catch(err => console.warn(err));
1295
+ }
1296
+ return true;
1297
+ }
1298
+ validateTransfer(tokenSlug, from, to, value, transferAll) {
1299
+ const errors = [];
1300
+ const keypair = keyring.getPair(from);
1301
+ let transferValue;
1302
+ if (!transferAll) {
1303
+ if (value === undefined) {
1304
+ errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Require transfer value'));
1305
+ }
1306
+ if (value) {
1307
+ transferValue = new BN(value);
1308
+ }
1309
+ }
1310
+ const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1311
+ if (!tokenInfo) {
1312
+ errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found token from registry'));
1313
+ }
1314
+ if (isEthereumAddress(from) && isEthereumAddress(to) && !_isNativeToken(tokenInfo) && !_isTokenEvmSmartContract(tokenInfo)) {
1315
+ errors.push(new TransactionError(BasicTxErrorType.INVALID_PARAMS, 'Not found ERC20 address for this token'));
1316
+ }
1317
+ return [errors, keypair, transferValue, tokenInfo];
1318
+ }
1319
+ async makeTransfer(inputData) {
1320
+ const {
1321
+ from,
1322
+ networkKey,
1323
+ to,
1324
+ tokenSlug,
1325
+ transferAll,
1326
+ value
1327
+ } = inputData;
1328
+ const [errors,,, tokenInfo] = this.validateTransfer(tokenSlug, from, to, value, transferAll);
1329
+ const warnings = [];
1330
+ const substrateApiMap = this.#koniState.getSubstrateApiMap();
1331
+ const evmApiMap = this.#koniState.getEvmApiMap();
1332
+ const chainInfo = this.#koniState.getChainInfo(networkKey);
1333
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(networkKey);
1334
+ const nativeTokenSlug = nativeTokenInfo.slug;
1335
+ const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1336
+ let chainType = ChainType.SUBSTRATE;
1337
+ const tokenBaseAmount = {
1338
+ value: '0',
1339
+ symbol: tokenInfo.symbol,
1340
+ decimals: tokenInfo.decimals || 0
1341
+ };
1342
+ const transferAmount = {
1343
+ ...tokenBaseAmount
1344
+ };
1345
+ let transaction;
1346
+
1347
+ // Get native token amount
1348
+ const freeBalance = await getFreeBalance(networkKey, from, substrateApiMap, evmApiMap, tokenSlug);
1349
+ if (isEthereumAddress(from) && isEthereumAddress(to)) {
1350
+ chainType = ChainType.EVM;
1351
+ const txVal = transferAll ? freeBalance : value || '0';
1352
+
1353
+ // Estimate with EVM API
1354
+ if (_isTokenEvmSmartContract(tokenInfo)) {
1355
+ [transaction, transferAmount.value] = await getERC20TransactionObject(_getContractAddressOfToken(tokenInfo), chainInfo, from, to, txVal, !!transferAll, evmApiMap);
1356
+ } else {
1357
+ [transaction, transferAmount.value] = await getEVMTransactionObject(chainInfo, to, txVal, !!transferAll, evmApiMap);
1358
+ }
1359
+ } else {
1360
+ const substrateApi = this.#koniState.getSubstrateApi(networkKey);
1361
+ [transaction, transferAmount.value] = await createTransferExtrinsic({
1362
+ transferAll: !!transferAll,
1363
+ value: value || '0',
1364
+ from: from,
1365
+ networkKey,
1366
+ tokenInfo,
1367
+ to: to,
1368
+ substrateApi
1369
+ });
1370
+ }
1371
+
1372
+ // Additional validator
1373
+ const additionalValidator = swTran => {
1374
+ if (new BN(freeBalance).lt(new BN(transferAmount.value))) {
1375
+ var _swTran$errors;
1376
+ (_swTran$errors = swTran.errors) === null || _swTran$errors === void 0 ? void 0 : _swTran$errors.push(new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE));
1377
+ }
1378
+ return Promise.resolve();
1379
+ };
1380
+ return this.#koniState.transactionService.handleTransaction({
1381
+ errors,
1382
+ warnings,
1383
+ address: from,
1384
+ chain: networkKey,
1385
+ chainType,
1386
+ transferNativeAmount: isTransferNativeToken ? transferAmount.value : '0',
1387
+ transaction,
1388
+ data: inputData,
1389
+ additionalValidator,
1390
+ extrinsicType: isTransferNativeToken ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.TRANSFER_TOKEN
1391
+ });
1392
+ }
1393
+ validateCrossChainTransfer(destinationNetworkKey, sendingTokenSlug, sender, sendingValue) {
1394
+ const errors = [];
1395
+ const keypair = keyring.getPair(sender);
1396
+ const transferValue = new BN(sendingValue);
1397
+ const originTokenInfo = this.#koniState.getAssetBySlug(sendingTokenSlug);
1398
+ const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destinationNetworkKey, sendingTokenSlug);
1399
+ if (!destinationTokenInfo) {
1400
+ errors.push(new TransactionError(TransferTxErrorType.INVALID_TOKEN, 'Not found token from registry'));
1401
+ }
1402
+ return [errors, keypair, transferValue, originTokenInfo, destinationTokenInfo];
1403
+ }
1404
+ async makeCrossChainTransfer(inputData) {
1405
+ const {
1406
+ destinationNetworkKey,
1407
+ from,
1408
+ originNetworkKey,
1409
+ sendingTokenSlug,
1410
+ to,
1411
+ value
1412
+ } = inputData;
1413
+ const [errors, fromKeyPair,, originTokenInfo, destinationTokenInfo] = this.validateCrossChainTransfer(destinationNetworkKey, sendingTokenSlug, from, value);
1414
+ let extrinsic = null;
1415
+ if (errors) {
1416
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
1417
+ }
1418
+ if (fromKeyPair && destinationTokenInfo) {
1419
+ const substrateApiMap = this.#koniState.getSubstrateApiMap();
1420
+ const chainInfoMap = this.#koniState.getChainInfoMap();
1421
+ extrinsic = await createXcmExtrinsic({
1422
+ destinationTokenInfo,
1423
+ originTokenInfo,
1424
+ sendingValue: value || '0',
1425
+ recipient: to,
1426
+ chainInfoMap: chainInfoMap,
1427
+ substrateApiMap: substrateApiMap
1428
+ });
1429
+ }
1430
+ return await this.#koniState.transactionService.handleTransaction({
1431
+ url: EXTENSION_REQUEST_URL,
1432
+ address: from,
1433
+ chain: originNetworkKey,
1434
+ transaction: extrinsic,
1435
+ data: inputData,
1436
+ extrinsicType: ExtrinsicType.TRANSFER_XCM,
1437
+ chainType: ChainType.SUBSTRATE,
1438
+ transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
1439
+ errors
1440
+ });
1441
+ }
1442
+ async evmNftSubmitTransaction(inputData) {
1443
+ const {
1444
+ networkKey,
1445
+ params,
1446
+ recipientAddress,
1447
+ senderAddress
1448
+ } = inputData;
1449
+ const contractAddress = params.contractAddress;
1450
+ const tokenId = params.tokenId;
1451
+ console.log(inputData);
1452
+ const transaction = await getERC721Transaction(this.#koniState.getEvmApi(networkKey), contractAddress, senderAddress, recipientAddress, tokenId);
1453
+ return await this.#koniState.transactionService.handleTransaction({
1454
+ address: senderAddress,
1455
+ chain: networkKey,
1456
+ chainType: ChainType.EVM,
1457
+ data: inputData,
1458
+ extrinsicType: ExtrinsicType.SEND_NFT,
1459
+ transaction,
1460
+ url: EXTENSION_REQUEST_URL
1461
+ });
1462
+ }
1463
+ upsertChain(data) {
1464
+ try {
1465
+ return this.#koniState.upsertChainInfo(data);
1466
+ } catch (e) {
1467
+ console.error(e);
1468
+ return false;
1469
+ }
1470
+ }
1471
+ removeCustomChain(networkKey) {
1472
+ return this.#koniState.removeCustomChain(networkKey);
1473
+ }
1474
+ disableChain(networkKey) {
1475
+ return this.#koniState.disableChain(networkKey);
1476
+ }
1477
+ enableChain(networkKey) {
1478
+ return this.#koniState.enableChain(networkKey);
1479
+ }
1480
+ async validateNetwork({
1481
+ existedChainSlug,
1482
+ provider
1483
+ }) {
1484
+ return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1485
+ }
1486
+ resetDefaultNetwork() {
1487
+ return this.#koniState.resetDefaultChains();
1488
+ }
1489
+ recoverDotSamaApi(networkKey) {
1490
+ try {
1491
+ return this.#koniState.refreshSubstrateApi(networkKey);
1492
+ } catch (e) {
1493
+ console.error('error recovering substrate api', e);
1494
+ return false;
1495
+ }
1496
+ }
1497
+ upsertCustomToken(data) {
1498
+ try {
1499
+ this.#koniState.upsertCustomToken(data);
1500
+ return true;
1501
+ } catch (e) {
1502
+ console.error('Error insert/update custom token', e);
1503
+ return false;
1504
+ }
1505
+ }
1506
+ async deleteCustomAsset(assetSlug) {
1507
+ const assetInfo = this.#koniState.getAssetBySlug(assetSlug);
1508
+ if (assetInfo && _isCustomAsset(assetSlug)) {
1509
+ if (_isAssetSmartContractNft(assetInfo)) {
1510
+ // check if deleting a smart contract NFT
1511
+ await this.#koniState.deleteNftCollection(assetInfo.originChain, _getContractAddressOfToken(assetInfo));
1512
+ }
1513
+ this.#koniState.deleteCustomAssets([assetSlug]);
1514
+ return true;
1515
+ }
1516
+ return false;
1517
+ }
1518
+ async validateCustomAsset(data) {
1519
+ return await this.#koniState.validateCustomAsset(data);
1520
+ }
1521
+ async subscribeAddressFreeBalance({
1522
+ address,
1523
+ networkKey,
1524
+ token
1525
+ }, id, port) {
1526
+ const cb = createSubscription(id, port);
1527
+ this.createUnsubscriptionHandle(id, await subscribeFreeBalance(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getEvmApiMap(), token, cb));
1528
+ port.onDisconnect.addListener(() => {
1529
+ this.cancelSubscription(id);
1530
+ });
1531
+ return id;
1532
+ }
1533
+ async transferCheckReferenceCount({
1534
+ address,
1535
+ networkKey
1536
+ }) {
1537
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
1538
+ return await checkReferenceCount(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1539
+ }
1540
+ async transferCheckSupporting({
1541
+ networkKey,
1542
+ tokenSlug
1543
+ }) {
1544
+ const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1545
+ return await checkSupportTransfer(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
1546
+ }
1547
+ transferGetExistentialDeposit({
1548
+ tokenSlug
1549
+ }) {
1550
+ const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
1551
+ return _getTokenMinAmount(tokenInfo);
1552
+ }
1553
+ async substrateNftSubmitTransaction(inputData) {
1554
+ const {
1555
+ params,
1556
+ recipientAddress,
1557
+ senderAddress
1558
+ } = inputData;
1559
+ const isSendingSelf = isRecipientSelf(senderAddress, recipientAddress);
1560
+
1561
+ // TODO: do better to detect tokenType
1562
+ const isPSP34 = params === null || params === void 0 ? void 0 : params.isPsp34;
1563
+ const networkKey = params === null || params === void 0 ? void 0 : params.networkKey;
1564
+ const apiProps = this.#koniState.getSubstrateApi(networkKey);
1565
+ const extrinsic = !isPSP34 ? getNftTransferExtrinsic(networkKey, apiProps, senderAddress, recipientAddress, params || {}) : await getPSP34TransferExtrinsic(networkKey, apiProps, senderAddress, recipientAddress, params || {});
1566
+ const rs = await this.#koniState.transactionService.handleTransaction({
1567
+ address: senderAddress,
1568
+ chain: networkKey,
1569
+ transaction: extrinsic,
1570
+ data: {
1571
+ ...inputData,
1572
+ isSendingSelf
1573
+ },
1574
+ extrinsicType: ExtrinsicType.SEND_NFT,
1575
+ chainType: ChainType.SUBSTRATE
1576
+ });
1577
+ return {
1578
+ ...rs,
1579
+ isSendingSelf
1580
+ };
1581
+ }
1582
+ enableChains(targetKeys) {
1583
+ try {
1584
+ for (const networkKey of targetKeys) {
1585
+ this.enableChain(networkKey);
1586
+ }
1587
+ } catch (e) {
1588
+ return false;
1589
+ }
1590
+ return true;
1591
+ }
1592
+ getAccountMeta({
1593
+ address
1594
+ }) {
1595
+ const pair = keyring.getPair(address);
1596
+ assert(pair, 'Unable to find pair');
1597
+ return {
1598
+ meta: pair.meta
1599
+ };
1600
+ }
1601
+ async isInWalletAccount(address) {
1602
+ return new Promise(resolve => {
1603
+ if (address) {
1604
+ accountsObservable.subject.subscribe(storedAccounts => {
1605
+ if (storedAccounts[address]) {
1606
+ resolve(true);
1607
+ }
1608
+ resolve(false);
1609
+ });
1610
+ } else {
1611
+ resolve(false);
1612
+ }
1613
+ });
1614
+ }
1615
+ accountsTie2({
1616
+ address,
1617
+ genesisHash
1618
+ }) {
1619
+ return this.#koniState.setAccountTie(address, genesisHash);
1620
+ }
1621
+ async accountsCreateExternalV2({
1622
+ address,
1623
+ genesisHash,
1624
+ isAllowed,
1625
+ isEthereum,
1626
+ isReadOnly,
1627
+ name
1628
+ }) {
1629
+ try {
1630
+ let result;
1631
+ try {
1632
+ const exists = keyring.getPair(address);
1633
+ if (exists) {
1634
+ if (exists.type === (isEthereum ? 'ethereum' : 'sr25519')) {
1635
+ return [{
1636
+ code: AccountExternalErrorCode.INVALID_ADDRESS,
1637
+ message: 'Account exists'
1638
+ }];
1639
+ }
1640
+ }
1641
+ } catch (e) {}
1642
+ if (isEthereum) {
1643
+ const chainInfoMap = this.#koniState.getChainInfoMap();
1644
+ let _gen = '';
1645
+ if (genesisHash) {
1646
+ for (const network of Object.values(chainInfoMap)) {
1647
+ if (_getEvmChainId(network) === parseInt(genesisHash)) {
1648
+ // TODO: pure EVM chains do not have genesisHash
1649
+ _gen = _getSubstrateGenesisHash(network);
1650
+ }
1651
+ }
1652
+ }
1653
+ result = keyring.keyring.addFromAddress(address, {
1654
+ name,
1655
+ isExternal: true,
1656
+ isReadOnly,
1657
+ genesisHash: _gen
1658
+ }, null, 'ethereum');
1659
+ keyring.saveAccount(result);
1660
+ } else {
1661
+ result = keyring.addExternal(address, {
1662
+ genesisHash,
1663
+ name,
1664
+ isReadOnly
1665
+ }).pair;
1666
+ }
1667
+ const _address = result.address;
1668
+ await new Promise(resolve => {
1669
+ this.#koniState.addAccountRef([_address], () => {
1670
+ resolve();
1671
+ });
1672
+ });
1673
+ await new Promise(resolve => {
1674
+ this._saveCurrentAccountAddress(_address, () => {
1675
+ this._addAddressToAuthList(_address, isAllowed);
1676
+ resolve();
1677
+ });
1678
+ });
1679
+ return [];
1680
+ } catch (e) {
1681
+ return [{
1682
+ code: AccountExternalErrorCode.KEYRING_ERROR,
1683
+ message: e.message
1684
+ }];
1685
+ }
1686
+ }
1687
+ async accountsCreateHardwareV2({
1688
+ accountIndex,
1689
+ address,
1690
+ addressOffset,
1691
+ genesisHash,
1692
+ hardwareType,
1693
+ isAllowed,
1694
+ name
1695
+ }) {
1696
+ const key = keyring.addHardware(address, hardwareType, {
1697
+ accountIndex,
1698
+ addressOffset,
1699
+ genesisHash,
1700
+ name,
1701
+ originGenesisHash: genesisHash
1702
+ });
1703
+ const result = key.pair;
1704
+ const _address = result.address;
1705
+ await new Promise(resolve => {
1706
+ this.#koniState.addAccountRef([_address], () => {
1707
+ resolve();
1708
+ });
1709
+ });
1710
+ await new Promise(resolve => {
1711
+ this._saveCurrentAccountAddress(_address, () => {
1712
+ this._addAddressToAuthList(_address, isAllowed || false);
1713
+ resolve();
1714
+ });
1715
+ });
1716
+ return true;
1717
+ }
1718
+ async accountsCreateHardwareMultiple({
1719
+ accounts
1720
+ }) {
1721
+ const addresses = [];
1722
+ if (!accounts.length) {
1723
+ throw new Error('No accounts to import');
1724
+ }
1725
+ for (const account of accounts) {
1726
+ const {
1727
+ accountIndex,
1728
+ address,
1729
+ addressOffset,
1730
+ genesisHash,
1731
+ hardwareType,
1732
+ name
1733
+ } = account;
1734
+ const key = keyring.addHardware(address, hardwareType, {
1735
+ accountIndex,
1736
+ addressOffset,
1737
+ genesisHash,
1738
+ name,
1739
+ originGenesisHash: genesisHash
1740
+ });
1741
+ const result = key.pair;
1742
+ const _address = result.address;
1743
+ addresses.push(_address);
1744
+ await new Promise(resolve => {
1745
+ this._addAddressToAuthList(_address, true);
1746
+ resolve();
1747
+ });
1748
+ }
1749
+ const currentAccount = await new Promise(resolve => {
1750
+ this.#koniState.getCurrentAccount(resolve);
1751
+ });
1752
+ const allGenesisHash = (currentAccount === null || currentAccount === void 0 ? void 0 : currentAccount.allGenesisHash) || undefined;
1753
+ if (addresses.length <= 1) {
1754
+ this.#koniState.setCurrentAccount({
1755
+ address: addresses[0],
1756
+ currentGenesisHash: null,
1757
+ allGenesisHash
1758
+ });
1759
+ } else {
1760
+ this.#koniState.setCurrentAccount({
1761
+ address: ALL_ACCOUNT_KEY,
1762
+ currentGenesisHash: allGenesisHash || null,
1763
+ allGenesisHash
1764
+ });
1765
+ }
1766
+ await new Promise(resolve => {
1767
+ this.#koniState.addAccountRef(addresses, () => {
1768
+ resolve();
1769
+ });
1770
+ });
1771
+ return true;
1772
+ }
1773
+ async accountsCreateWithSecret({
1774
+ isAllow,
1775
+ isEthereum,
1776
+ name,
1777
+ publicKey,
1778
+ secretKey
1779
+ }) {
1780
+ try {
1781
+ let keyringPair = null;
1782
+ if (isEthereum) {
1783
+ const _secret = hexStripPrefix(secretKey);
1784
+ if (_secret.length === 64) {
1785
+ const suri = `0x${_secret}`;
1786
+ const {
1787
+ phrase
1788
+ } = keyExtractSuri(suri);
1789
+ if (isHex(phrase) && isHex(phrase, 256)) {
1790
+ const type = 'ethereum';
1791
+ keyringPair = keyring.addUri(getSuri(suri, type), {
1792
+ name: name
1793
+ }, type).pair;
1794
+ }
1795
+ }
1796
+ } else {
1797
+ keyringPair = keyring.keyring.addFromPair({
1798
+ publicKey: hexToU8a(publicKey),
1799
+ secretKey: hexToU8a(secretKey)
1800
+ }, {
1801
+ name
1802
+ });
1803
+ keyring.addPair(keyringPair, true);
1804
+ }
1805
+ if (!keyringPair) {
1806
+ return {
1807
+ success: false,
1808
+ errors: [{
1809
+ code: AccountExternalErrorCode.KEYRING_ERROR,
1810
+ message: 'Invalid keyring'
1811
+ }]
1812
+ };
1813
+ }
1814
+ const _address = keyringPair.address;
1815
+ await new Promise(resolve => {
1816
+ this.#koniState.addAccountRef([_address], () => {
1817
+ resolve();
1818
+ });
1819
+ });
1820
+ await new Promise(resolve => {
1821
+ this._saveCurrentAccountAddress(_address, () => {
1822
+ this._addAddressToAuthList(_address, isAllow);
1823
+ resolve();
1824
+ });
1825
+ });
1826
+ return {
1827
+ errors: [],
1828
+ success: true
1829
+ };
1830
+ } catch (e) {
1831
+ return {
1832
+ success: false,
1833
+ errors: [{
1834
+ code: AccountExternalErrorCode.KEYRING_ERROR,
1835
+ message: e.message
1836
+ }]
1837
+ };
1838
+ }
1839
+ }
1840
+
1841
+ /// External account
1842
+
1843
+ rejectExternalRequest(request) {
1844
+ const {
1845
+ id,
1846
+ message,
1847
+ throwError
1848
+ } = request;
1849
+ const promise = this.#koniState.getExternalRequest(id);
1850
+ if (promise.status === ExternalRequestPromiseStatus.PENDING && promise.reject) {
1851
+ if (throwError) {
1852
+ promise.reject(new Error(message));
1853
+ } else {
1854
+ promise.reject();
1855
+ }
1856
+ this.#koniState.updateExternalRequest(id, {
1857
+ status: ExternalRequestPromiseStatus.REJECTED,
1858
+ message: message,
1859
+ reject: undefined,
1860
+ resolve: undefined
1861
+ });
1862
+ }
1863
+ }
1864
+ resolveQrTransfer(request) {
1865
+ const {
1866
+ data,
1867
+ id
1868
+ } = request;
1869
+ const promise = this.#koniState.getExternalRequest(id);
1870
+ if (promise.status === ExternalRequestPromiseStatus.PENDING) {
1871
+ promise.resolve && promise.resolve(data);
1872
+ this.#koniState.updateExternalRequest(id, {
1873
+ status: ExternalRequestPromiseStatus.COMPLETED,
1874
+ reject: undefined,
1875
+ resolve: undefined
1876
+ });
1877
+ }
1878
+ }
1879
+ subscribeConfirmations(id, port) {
1880
+ const cb = createSubscription(id, port);
1881
+ const subscription = this.#koniState.getConfirmationsQueueSubject().subscribe(cb);
1882
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
1883
+ port.onDisconnect.addListener(() => {
1884
+ this.cancelSubscription(id);
1885
+ });
1886
+ return this.#koniState.getConfirmationsQueueSubject().getValue();
1887
+ }
1888
+ async completeConfirmation(request) {
1889
+ return await this.#koniState.completeConfirmation(request);
1890
+ }
1891
+
1892
+ /// Sign Qr
1893
+
1894
+ getNetworkJsonByChainId(chainId) {
1895
+ const chainInfoMap = this.#koniState.getChainInfoMap();
1896
+ if (!chainId) {
1897
+ for (const n in chainInfoMap) {
1898
+ if (!Object.prototype.hasOwnProperty.call(chainInfoMap, n)) {
1899
+ continue;
1900
+ }
1901
+ const networkInfo = chainInfoMap[n];
1902
+ if (_isChainEvmCompatible(networkInfo)) {
1903
+ return networkInfo;
1904
+ }
1905
+ }
1906
+ return null;
1907
+ }
1908
+ for (const n in chainInfoMap) {
1909
+ if (!Object.prototype.hasOwnProperty.call(chainInfoMap, n)) {
1910
+ continue;
1911
+ }
1912
+ const networkInfo = chainInfoMap[n];
1913
+ if (_getEvmChainId(networkInfo) === chainId) {
1914
+ return networkInfo;
1915
+ }
1916
+ }
1917
+ return null;
1918
+ }
1919
+
1920
+ // Parse transaction
1921
+
1922
+ parseSubstrateTransaction({
1923
+ data,
1924
+ networkKey
1925
+ }) {
1926
+ const apiProps = this.#koniState.getSubstrateApi(networkKey);
1927
+ const apiPromise = apiProps.api;
1928
+ return parseSubstrateTransaction(data, apiPromise);
1929
+ }
1930
+ async parseEVMRLP({
1931
+ data
1932
+ }) {
1933
+ return await parseEvmRlp(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
1934
+ }
1935
+
1936
+ // Sign
1937
+
1938
+ qrSignSubstrate({
1939
+ address,
1940
+ data,
1941
+ networkKey
1942
+ }) {
1943
+ const pair = keyring.getPair(address);
1944
+ assert(pair, 'Unable to find pair');
1945
+ if (pair.isLocked) {
1946
+ keyring.unlockPair(pair.address);
1947
+ }
1948
+ let signed = hexStripPrefix(u8aToHex(pair.sign(data, {
1949
+ withType: true
1950
+ })));
1951
+ const network = this.#koniState.getChainInfo(networkKey);
1952
+ if (_isChainEvmCompatible(network)) {
1953
+ signed = signed.substring(2);
1954
+ }
1955
+ return {
1956
+ signature: signed
1957
+ };
1958
+ }
1959
+ async qrSignEVM({
1960
+ address,
1961
+ chainId,
1962
+ message,
1963
+ type
1964
+ }) {
1965
+ let signed;
1966
+ const network = this.getNetworkJsonByChainId(chainId);
1967
+ if (!network) {
1968
+ throw new Error('Cannot find network');
1969
+ }
1970
+ const pair = keyring.getPair(address);
1971
+ if (!pair) {
1972
+ throw Error('Unable to find pair');
1973
+ }
1974
+ if (pair.isLocked) {
1975
+ keyring.unlockPair(pair.address);
1976
+ }
1977
+ if (type === 'message') {
1978
+ let data = message;
1979
+ if (isHex(message)) {
1980
+ data = message;
1981
+ } else if (isAscii(message)) {
1982
+ data = `0x${message}`;
1983
+ }
1984
+ signed = await pair.evmSigner.signMessage(data, 'personal_sign');
1985
+ } else {
1986
+ const tx = createTransactionFromRLP(message);
1987
+ if (!tx) {
1988
+ throw new Error(`Cannot create tx from ${message}`);
1989
+ }
1990
+ const txObject = {
1991
+ gasPrice: new BigN(tx.gasPrice).toNumber(),
1992
+ to: tx.action,
1993
+ value: new BigN(tx.value).toNumber(),
1994
+ data: tx.data,
1995
+ nonce: new BigN(tx.nonce).toNumber(),
1996
+ gas: new BigN(tx.gas).toNumber()
1997
+ };
1998
+ const common = Common.forCustomChain('mainnet', {
1999
+ name: network.name,
2000
+ networkId: _getEvmChainId(network),
2001
+ chainId: _getEvmChainId(network)
2002
+ }, 'petersburg');
2003
+
2004
+ // @ts-ignore
2005
+ const transaction = new Transaction(txObject, {
2006
+ common
2007
+ });
2008
+ pair.evmSigner.signTransaction(transaction);
2009
+ signed = signatureToHex({
2010
+ r: u8aToHex(transaction.r),
2011
+ s: u8aToHex(transaction.s),
2012
+ v: u8aToHex(transaction.v)
2013
+ });
2014
+ }
2015
+ return {
2016
+ signature: hexStripPrefix(signed)
2017
+ };
2018
+ }
2019
+ async subscribeChainStakingMetadata(id, port) {
2020
+ const cb = createSubscription(id, port);
2021
+ const chainStakingMetadata = this.#koniState.subscribeChainStakingMetadata().subscribe({
2022
+ next: rs => {
2023
+ cb(rs);
2024
+ }
2025
+ });
2026
+ this.createUnsubscriptionHandle(id, chainStakingMetadata.unsubscribe);
2027
+ port.onDisconnect.addListener(() => {
2028
+ this.cancelSubscription(id);
2029
+ });
2030
+ return this.#koniState.getChainStakingMetadata();
2031
+ }
2032
+ async subscribeStakingNominatorMetadata(id, port) {
2033
+ const cb = createSubscription(id, port);
2034
+ const nominatorMetadata = this.#koniState.subscribeNominatorMetadata().subscribe({
2035
+ next: rs => {
2036
+ cb(rs);
2037
+ }
2038
+ });
2039
+ this.createUnsubscriptionHandle(id, nominatorMetadata.unsubscribe);
2040
+ port.onDisconnect.addListener(() => {
2041
+ this.cancelSubscription(id);
2042
+ });
2043
+ return this.#koniState.getNominatorMetadata();
2044
+ }
2045
+ async getBondingOptions({
2046
+ chain,
2047
+ type
2048
+ }) {
2049
+ const apiProps = this.#koniState.getSubstrateApi(chain);
2050
+ const chainInfo = this.#koniState.getChainInfo(chain);
2051
+ const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
2052
+ if (!chainStakingMetadata) {
2053
+ return;
2054
+ }
2055
+ const {
2056
+ decimals
2057
+ } = _getChainNativeTokenBasicInfo(chainInfo);
2058
+ return await getValidatorsInfo(chain, apiProps, decimals, chainStakingMetadata);
2059
+ }
2060
+ async getNominationPoolOptions(chain) {
2061
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2062
+ return await getNominationPoolsInfo(chain, substrateApi);
2063
+ }
2064
+ async submitBonding(inputData) {
2065
+ const {
2066
+ amount,
2067
+ chain,
2068
+ nominatorMetadata,
2069
+ selectedValidators
2070
+ } = inputData;
2071
+ if (!amount || !nominatorMetadata || !selectedValidators) {
2072
+ // Todo: Check and return error here
2073
+
2074
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2075
+ }
2076
+ const chainInfo = this.#koniState.getChainInfo(chain);
2077
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2078
+ const extrinsic = await getBondingExtrinsic(chainInfo, amount, nominatorMetadata, selectedValidators, substrateApi);
2079
+ return await this.#koniState.transactionService.handleTransaction({
2080
+ address: nominatorMetadata.address,
2081
+ chain: chain,
2082
+ chainType: ChainType.SUBSTRATE,
2083
+ data: inputData,
2084
+ extrinsicType: ExtrinsicType.STAKING_BOND,
2085
+ transaction: extrinsic,
2086
+ url: EXTENSION_REQUEST_URL
2087
+ });
2088
+ }
2089
+ async submitUnbonding(inputData) {
2090
+ const {
2091
+ amount,
2092
+ chain,
2093
+ nominatorMetadata,
2094
+ validatorAddress
2095
+ } = inputData;
2096
+ if (!amount || !nominatorMetadata) {
2097
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2098
+ }
2099
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2100
+ const extrinsic = await getUnbondingExtrinsic(nominatorMetadata, amount, chain, substrateApi, validatorAddress);
2101
+ return await this.#koniState.transactionService.handleTransaction({
2102
+ address: nominatorMetadata.address,
2103
+ chain: chain,
2104
+ transaction: extrinsic,
2105
+ data: inputData,
2106
+ extrinsicType: ExtrinsicType.STAKING_UNBOND,
2107
+ chainType: ChainType.SUBSTRATE
2108
+ });
2109
+ }
2110
+ async submitStakeWithdrawal(inputData) {
2111
+ const {
2112
+ chain,
2113
+ nominatorMetadata,
2114
+ validatorAddress
2115
+ } = inputData;
2116
+ if (!nominatorMetadata) {
2117
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2118
+ }
2119
+ const dotSamaApi = this.#koniState.getSubstrateApi(chain);
2120
+ const extrinsic = await getWithdrawalExtrinsic(dotSamaApi, chain, nominatorMetadata, validatorAddress);
2121
+ return await this.#koniState.transactionService.handleTransaction({
2122
+ address: nominatorMetadata.address,
2123
+ chain: chain,
2124
+ transaction: extrinsic,
2125
+ data: inputData,
2126
+ extrinsicType: ExtrinsicType.STAKING_WITHDRAW,
2127
+ chainType: ChainType.SUBSTRATE
2128
+ });
2129
+ }
2130
+ async submitStakeClaimReward(inputData) {
2131
+ const {
2132
+ address,
2133
+ chain,
2134
+ stakingType,
2135
+ validatorAddress
2136
+ } = inputData;
2137
+ if (!address) {
2138
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2139
+ }
2140
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2141
+ const extrinsic = await getClaimRewardExtrinsic(substrateApi, chain, address, stakingType, validatorAddress);
2142
+ return await this.#koniState.transactionService.handleTransaction({
2143
+ address,
2144
+ chain: chain,
2145
+ transaction: extrinsic,
2146
+ data: inputData,
2147
+ extrinsicType: ExtrinsicType.STAKING_CLAIM_REWARD,
2148
+ chainType: ChainType.SUBSTRATE
2149
+ });
2150
+ }
2151
+ async submitCancelStakeWithdrawal(inputData) {
2152
+ const {
2153
+ address,
2154
+ chain,
2155
+ selectedUnstaking
2156
+ } = inputData;
2157
+ if (!chain || !selectedUnstaking) {
2158
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2159
+ }
2160
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2161
+ const extrinsic = await getCancelWithdrawalExtrinsic(substrateApi, chain, selectedUnstaking);
2162
+ return await this.#koniState.transactionService.handleTransaction({
2163
+ address,
2164
+ chain,
2165
+ transaction: extrinsic,
2166
+ data: inputData,
2167
+ extrinsicType: ExtrinsicType.STAKING_CANCEL_WITHDRAWAL,
2168
+ chainType: ChainType.SUBSTRATE
2169
+ });
2170
+ }
2171
+ async submitPoolingBonding(inputData) {
2172
+ const {
2173
+ address,
2174
+ amount,
2175
+ chain,
2176
+ nominatorMetadata,
2177
+ selectedPool
2178
+ } = inputData;
2179
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2180
+ const extrinsic = await getPoolingBondingExtrinsic(substrateApi, amount, selectedPool.id, nominatorMetadata);
2181
+ return await this.#koniState.transactionService.handleTransaction({
2182
+ address,
2183
+ chain,
2184
+ transaction: extrinsic,
2185
+ data: inputData,
2186
+ extrinsicType: ExtrinsicType.STAKING_BOND,
2187
+ chainType: ChainType.SUBSTRATE
2188
+ });
2189
+ }
2190
+ async submitPoolingUnbonding(inputData) {
2191
+ const {
2192
+ amount,
2193
+ chain,
2194
+ nominatorMetadata
2195
+ } = inputData;
2196
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2197
+ const extrinsic = await getPoolingUnbondingExtrinsic(substrateApi, amount, nominatorMetadata);
2198
+ return await this.#koniState.transactionService.handleTransaction({
2199
+ address: nominatorMetadata.address,
2200
+ chain,
2201
+ transaction: extrinsic,
2202
+ data: inputData,
2203
+ extrinsicType: ExtrinsicType.STAKING_UNBOND,
2204
+ chainType: ChainType.SUBSTRATE
2205
+ });
2206
+ }
2207
+ async submitPoolingWithdrawal(inputData) {
2208
+ const {
2209
+ chain,
2210
+ isReBond,
2211
+ nominatorMetadata
2212
+ } = inputData;
2213
+ const substrateApi = this.#koniState.getSubstrateApi(chain);
2214
+ const extrinsic = await getPoolingWithdrawalExtrinsic(substrateApi, nominatorMetadata, isReBond);
2215
+ return await this.#koniState.transactionService.handleTransaction({
2216
+ address: nominatorMetadata.address,
2217
+ chain,
2218
+ transaction: extrinsic,
2219
+ data: inputData,
2220
+ extrinsicType: ExtrinsicType.STAKING_WITHDRAW,
2221
+ chainType: ChainType.SUBSTRATE
2222
+ });
2223
+ }
2224
+
2225
+ // EVM Transaction
2226
+ async parseContractInput({
2227
+ chainId,
2228
+ contract,
2229
+ data
2230
+ }) {
2231
+ const network = this.getNetworkJsonByChainId(chainId);
2232
+ return await parseContractInput(data, contract, network);
2233
+ }
2234
+ async submitTuringStakeCompounding(inputData) {
2235
+ const {
2236
+ accountMinimum,
2237
+ address,
2238
+ bondedAmount,
2239
+ collatorAddress,
2240
+ networkKey
2241
+ } = inputData;
2242
+ if (!address) {
2243
+ return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INVALID_PARAMS)]);
2244
+ }
2245
+ const dotSamaApi = this.#koniState.getSubstrateApi(networkKey);
2246
+ const chainInfo = this.#koniState.getChainInfo(networkKey);
2247
+ const {
2248
+ decimals
2249
+ } = _getChainNativeTokenBasicInfo(chainInfo);
2250
+ const parsedAccountMinimum = parseFloat(accountMinimum) * 10 ** decimals;
2251
+ const extrinsic = await getTuringCompoundExtrinsic(dotSamaApi, address, collatorAddress, parsedAccountMinimum.toString(), bondedAmount);
2252
+ return await this.#koniState.transactionService.handleTransaction({
2253
+ address,
2254
+ chain: networkKey,
2255
+ transaction: extrinsic,
2256
+ data: inputData,
2257
+ extrinsicType: ExtrinsicType.STAKING_COMPOUNDING,
2258
+ chainType: ChainType.SUBSTRATE
2259
+ });
2260
+ }
2261
+ async submitTuringCancelStakeCompound(inputData) {
2262
+ const {
2263
+ address,
2264
+ networkKey,
2265
+ taskId
2266
+ } = inputData;
2267
+ const txState = {};
2268
+ if (!address) {
2269
+ txState.txError = true;
2270
+ return txState;
2271
+ }
2272
+ const dotSamaApi = this.#koniState.getSubstrateApi(networkKey);
2273
+ const extrinsic = await getTuringCancelCompoundingExtrinsic(dotSamaApi, taskId);
2274
+ return await this.#koniState.transactionService.handleTransaction({
2275
+ address,
2276
+ chain: networkKey,
2277
+ transaction: extrinsic,
2278
+ data: inputData,
2279
+ extrinsicType: ExtrinsicType.STAKING_CANCEL_COMPOUNDING,
2280
+ chainType: ChainType.SUBSTRATE
2281
+ });
2282
+ }
2283
+ async wasmNftGetTransaction({
2284
+ networkKey,
2285
+ params,
2286
+ recipientAddress,
2287
+ senderAddress
2288
+ }) {
2289
+ const contractAddress = params.contractAddress;
2290
+ const onChainOption = params.onChainOption;
2291
+ try {
2292
+ return await getPSP34Transaction(this.#koniState.getEvmApiMap(), this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey), networkKey, contractAddress, senderAddress, recipientAddress, onChainOption);
2293
+ } catch (e) {
2294
+ console.error('Error getting WASM NFT transaction', e);
2295
+ return {
2296
+ error: true,
2297
+ balanceError: false
2298
+ };
2299
+ }
2300
+ }
2301
+ keyringStateSubscribe(id, port) {
2302
+ const cb = createSubscription(id, port);
2303
+ const subscription = this.#koniState.subscribeKeyringState().subscribe(value => cb(value));
2304
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
2305
+ port.onDisconnect.addListener(() => {
2306
+ this.cancelSubscription(id);
2307
+ });
2308
+ return this.#koniState.getKeyringState();
2309
+ }
2310
+ keyringChangeMasterPassword({
2311
+ createNew,
2312
+ newPassword,
2313
+ oldPassword
2314
+ }) {
2315
+ try {
2316
+ // Remove isMasterPassword meta if createNew
2317
+ if (createNew) {
2318
+ const pairs = keyring.getPairs();
2319
+ for (const pair of pairs) {
2320
+ const meta = {
2321
+ ...pair.meta,
2322
+ isMasterPassword: false
2323
+ };
2324
+ if (!meta.originGenesisHash) {
2325
+ meta.genesisHash = '';
2326
+ }
2327
+ pair.setMeta(meta);
2328
+ keyring.saveAccountMeta(pair, pair.meta);
2329
+ }
2330
+ }
2331
+ keyring.changeMasterPassword(newPassword, oldPassword);
2332
+ } catch (e) {
2333
+ console.error(e);
2334
+ return {
2335
+ errors: [e.message],
2336
+ status: false
2337
+ };
2338
+ }
2339
+ this.#koniState.setKeyringState({
2340
+ hasMasterPassword: true,
2341
+ isLocked: false,
2342
+ isReady: true
2343
+ });
2344
+ return {
2345
+ status: true,
2346
+ errors: []
2347
+ };
2348
+ }
2349
+ keyringMigrateMasterPassword({
2350
+ address,
2351
+ password
2352
+ }) {
2353
+ try {
2354
+ keyring.migrateWithMasterPassword(address, password);
2355
+ } catch (e) {
2356
+ console.error(e);
2357
+ return {
2358
+ errors: [e.message],
2359
+ status: false
2360
+ };
2361
+ }
2362
+ return {
2363
+ status: true,
2364
+ errors: []
2365
+ };
2366
+ }
2367
+ keyringUnlock({
2368
+ password
2369
+ }) {
2370
+ try {
2371
+ keyring.unlockKeyring(password);
2372
+ } catch (e) {
2373
+ return {
2374
+ errors: [e.message],
2375
+ status: false
2376
+ };
2377
+ }
2378
+ this.#koniState.setKeyringState({
2379
+ isReady: true,
2380
+ hasMasterPassword: true,
2381
+ isLocked: false
2382
+ });
2383
+ return {
2384
+ status: true,
2385
+ errors: []
2386
+ };
2387
+ }
2388
+ keyringLock() {
2389
+ keyring.lockAll();
2390
+ this.#koniState.setKeyringState({
2391
+ isReady: true,
2392
+ hasMasterPassword: true,
2393
+ isLocked: true
2394
+ });
2395
+ }
2396
+ keyringExportMnemonic({
2397
+ address,
2398
+ password
2399
+ }) {
2400
+ const pair = keyring.getPair(address);
2401
+ const result = pair.exportMnemonic(password);
2402
+ return {
2403
+ result
2404
+ };
2405
+ }
2406
+
2407
+ /// Signing external request
2408
+ signingApprovePasswordV2({
2409
+ id
2410
+ }) {
2411
+ const queued = this.#koniState.getSignRequest(id);
2412
+ assert(queued, 'Unable to find request');
2413
+ const {
2414
+ reject,
2415
+ request,
2416
+ resolve
2417
+ } = queued;
2418
+ const pair = keyring.getPair(queued.account.address);
2419
+
2420
+ // unlike queued.account.address the following
2421
+ // address is encoded with the default prefix
2422
+ // which what is used for password caching mapping
2423
+ const {
2424
+ address
2425
+ } = pair;
2426
+ if (!pair) {
2427
+ reject(new Error('Unable to find pair'));
2428
+ return false;
2429
+ }
2430
+ if (pair.isLocked) {
2431
+ keyring.unlockPair(address);
2432
+ }
2433
+ const {
2434
+ payload
2435
+ } = request;
2436
+ const registry = new TypeRegistry();
2437
+ if (isJsonPayload(payload)) {
2438
+ // Get the metadata for the genesisHash
2439
+ const currentMetadata = this.#koniState.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
2440
+
2441
+ // set the registry before calling the sign function
2442
+ registry.setSignedExtensions(payload.signedExtensions, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.userExtensions);
2443
+ if (currentMetadata) {
2444
+ registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
2445
+ }
2446
+ }
2447
+ const result = request.sign(registry, pair);
2448
+ resolve({
2449
+ id,
2450
+ ...result
2451
+ });
2452
+ return true;
2453
+ }
2454
+
2455
+ /// Derive account
2456
+
2457
+ derivationCreateMultiple({
2458
+ isAllowed,
2459
+ items,
2460
+ parentAddress
2461
+ }) {
2462
+ const parentPair = keyring.getPair(parentAddress);
2463
+ const isEvm = parentPair.type === 'ethereum';
2464
+ if (parentPair.isLocked) {
2465
+ keyring.unlockPair(parentPair.address);
2466
+ }
2467
+ const createChild = ({
2468
+ name,
2469
+ suri
2470
+ }) => {
2471
+ const meta = {
2472
+ name: name,
2473
+ parentAddress
2474
+ };
2475
+ if (isEvm) {
2476
+ let index = 0;
2477
+ try {
2478
+ const reg = /^\d+$/;
2479
+ const path = suri.split('//')[1];
2480
+ if (reg.test(path)) {
2481
+ index = parseInt(path);
2482
+ }
2483
+ } catch (e) {}
2484
+ if (!index) {
2485
+ throw Error('Invalid derive path');
2486
+ }
2487
+ meta.suri = `//${index}`;
2488
+ return parentPair.deriveEvm(index, meta);
2489
+ } else {
2490
+ meta.suri = suri;
2491
+ return parentPair.derive(suri, meta);
2492
+ }
2493
+ };
2494
+ const result = [];
2495
+ for (const item of items) {
2496
+ try {
2497
+ const childPair = createChild(item);
2498
+ const address = childPair.address;
2499
+ keyring.addPair(childPair, true);
2500
+ this._addAddressToAuthList(address, isAllowed);
2501
+ result.push(childPair);
2502
+ } catch (e) {
2503
+ console.log(`Fail to derive from ${parentAddress} with path ${item.suri}`, e);
2504
+ }
2505
+ }
2506
+ if (result.length === 1) {
2507
+ this._saveCurrentAccountAddress(result[0].address);
2508
+ } else {
2509
+ this.#koniState.setCurrentAccount({
2510
+ address: ALL_ACCOUNT_KEY,
2511
+ currentGenesisHash: null
2512
+ });
2513
+ }
2514
+ return true;
2515
+ }
2516
+ derivationCreateV3({
2517
+ address: parentAddress
2518
+ }) {
2519
+ const parentPair = keyring.getPair(parentAddress);
2520
+ const isEvm = parentPair.type === 'ethereum';
2521
+ if (parentPair.isLocked) {
2522
+ keyring.unlockPair(parentPair.address);
2523
+ }
2524
+ const pairs = keyring.getPairs();
2525
+ const children = pairs.filter(p => p.meta.parentAddress === parentAddress);
2526
+ const name = `Account ${pairs.length}`;
2527
+ let index = isEvm ? 1 : 0;
2528
+ let valid = false;
2529
+ do {
2530
+ const exist = children.find(p => p.meta.suri === `//${index}`);
2531
+ if (exist) {
2532
+ index++;
2533
+ } else {
2534
+ valid = true;
2535
+ }
2536
+ } while (!valid);
2537
+ const meta = {
2538
+ name,
2539
+ parentAddress,
2540
+ suri: `//${index}`
2541
+ };
2542
+ const childPair = isEvm ? parentPair.deriveEvm(index, meta) : parentPair.derive(meta.suri, meta);
2543
+ const address = childPair.address;
2544
+ this._saveCurrentAccountAddress(address, () => {
2545
+ keyring.addPair(childPair, true);
2546
+ this._addAddressToAuthList(address, true);
2547
+ });
2548
+ return true;
2549
+ }
2550
+ validateDerivePath({
2551
+ parentAddress,
2552
+ suri
2553
+ }) {
2554
+ const parentPair = keyring.getPair(parentAddress);
2555
+ const isEvm = parentPair.type === 'ethereum';
2556
+ if (parentPair.isLocked) {
2557
+ keyring.unlockPair(parentPair.address);
2558
+ }
2559
+ const meta = {
2560
+ parentAddress
2561
+ };
2562
+ let childPair;
2563
+ if (isEvm) {
2564
+ let index = 0;
2565
+ try {
2566
+ const reg = /^\d+$/;
2567
+ const path = suri.split('//')[1];
2568
+ if (reg.test(path)) {
2569
+ index = parseInt(path);
2570
+ }
2571
+ } catch (e) {}
2572
+ if (!index) {
2573
+ throw Error('Invalid derive path');
2574
+ }
2575
+ meta.suri = `//${index}`;
2576
+ childPair = parentPair.deriveEvm(index, meta);
2577
+ } else {
2578
+ meta.suri = suri;
2579
+ childPair = parentPair.derive(suri, meta);
2580
+ }
2581
+ return {
2582
+ address: childPair.address,
2583
+ suri: meta.suri
2584
+ };
2585
+ }
2586
+ getListDeriveAccounts({
2587
+ limit,
2588
+ page,
2589
+ parentAddress
2590
+ }) {
2591
+ const parentPair = keyring.getPair(parentAddress);
2592
+ const isEvm = parentPair.type === 'ethereum';
2593
+ if (parentPair.isLocked) {
2594
+ keyring.unlockPair(parentPair.address);
2595
+ }
2596
+ const start = (page - 1) * limit + (isEvm ? 1 : 0);
2597
+ const end = start + limit;
2598
+ const result = [];
2599
+ for (let i = start; i < end; i++) {
2600
+ const suri = `//${i}`;
2601
+ const pair = isEvm ? parentPair.deriveEvm(i, {}) : parentPair.derive(suri, {});
2602
+ result.push({
2603
+ address: pair.address,
2604
+ suri: suri
2605
+ });
2606
+ }
2607
+ return {
2608
+ result: result
2609
+ };
2610
+ }
2611
+
2612
+ // ChainService -------------------------------------------------
2613
+ subscribeChainInfoMap(id, port) {
2614
+ const cb = createSubscription(id, port);
2615
+ const chainInfoMapSubscription = this.#koniState.subscribeChainInfoMap().subscribe({
2616
+ next: rs => {
2617
+ cb(rs);
2618
+ }
2619
+ });
2620
+ this.createUnsubscriptionHandle(id, chainInfoMapSubscription.unsubscribe);
2621
+ port.onDisconnect.addListener(() => {
2622
+ this.cancelSubscription(id);
2623
+ });
2624
+ return this.#koniState.getChainInfoMap();
2625
+ }
2626
+ subscribeChainStateMap(id, port) {
2627
+ const cb = createSubscription(id, port);
2628
+ const chainStateMapSubscription = this.#koniState.subscribeChainStateMap().subscribe({
2629
+ next: rs => {
2630
+ cb(rs);
2631
+ }
2632
+ });
2633
+ this.createUnsubscriptionHandle(id, chainStateMapSubscription.unsubscribe);
2634
+ port.onDisconnect.addListener(() => {
2635
+ this.cancelSubscription(id);
2636
+ });
2637
+ return this.#koniState.getChainStateMap();
2638
+ }
2639
+ subscribeAssetRegistry(id, port) {
2640
+ const cb = createSubscription(id, port);
2641
+ const assetRegistrySubscription = this.#koniState.subscribeAssetRegistry().subscribe({
2642
+ next: rs => {
2643
+ cb(rs);
2644
+ }
2645
+ });
2646
+ this.createUnsubscriptionHandle(id, assetRegistrySubscription.unsubscribe);
2647
+ port.onDisconnect.addListener(() => {
2648
+ this.cancelSubscription(id);
2649
+ });
2650
+ return this.#koniState.getAssetRegistry();
2651
+ }
2652
+ subscribeMultiChainAssetMap(id, port) {
2653
+ const cb = createSubscription(id, port);
2654
+ const multiChainAssetSubscription = this.#koniState.subscribeMultiChainAssetMap().subscribe({
2655
+ next: rs => {
2656
+ cb(rs);
2657
+ }
2658
+ });
2659
+ this.createUnsubscriptionHandle(id, multiChainAssetSubscription.unsubscribe);
2660
+ port.onDisconnect.addListener(() => {
2661
+ this.cancelSubscription(id);
2662
+ });
2663
+ return this.#koniState.getMultiChainAssetMap();
2664
+ }
2665
+ getSupportedSmartContractTypes() {
2666
+ return this.#koniState.getSupportedSmartContractTypes();
2667
+ }
2668
+ getTransaction({
2669
+ id
2670
+ }) {
2671
+ const {
2672
+ transaction,
2673
+ ...transactionResult
2674
+ } = this.#koniState.transactionService.getTransaction(id);
2675
+ return transactionResult;
2676
+ }
2677
+ subscribeTransactions(id, port) {
2678
+ const cb = createSubscription(id, port);
2679
+ function convertRs(rs) {
2680
+ return Object.fromEntries(Object.entries(rs).map(([key, value]) => {
2681
+ const {
2682
+ transaction,
2683
+ ...transactionResult
2684
+ } = value;
2685
+ return [key, transactionResult];
2686
+ }));
2687
+ }
2688
+ const transactionsSubject = this.#koniState.transactionService.getTransactionSubject();
2689
+ const transactionsSubscription = transactionsSubject.subscribe(rs => {
2690
+ cb(convertRs(rs));
2691
+ });
2692
+ port.onDisconnect.addListener(() => {
2693
+ transactionsSubscription.unsubscribe();
2694
+ this.cancelSubscription(id);
2695
+ });
2696
+ return convertRs(transactionsSubject.getValue());
2697
+ }
2698
+
2699
+ // --------------------------------------------------------------
2700
+ // eslint-disable-next-line @typescript-eslint/require-await
2701
+ async handle(id, type, request, port) {
2702
+ switch (type) {
2703
+ /// Clone from PolkadotJs
2704
+ case 'pri(accounts.create.external)':
2705
+ return this.accountsCreateExternal(request);
2706
+ case 'pri(accounts.create.hardware)':
2707
+ return this.accountsCreateHardware(request);
2708
+ case 'pri(accounts.create.suri)':
2709
+ return this.accountsCreateSuri(request);
2710
+ case 'pri(accounts.changePassword)':
2711
+ return this.accountsChangePassword(request);
2712
+ case 'pri(accounts.edit)':
2713
+ return this.accountsEdit(request);
2714
+ case 'pri(accounts.export)':
2715
+ return this.accountsExport(request);
2716
+ case 'pri(accounts.show)':
2717
+ return this.accountsShow(request);
2718
+ case 'pri(accounts.subscribe)':
2719
+ return this.accountsSubscribe(id, port);
2720
+ case 'pri(accounts.validate)':
2721
+ return this.accountsValidate(request);
2722
+ case 'pri(metadata.approve)':
2723
+ return this.metadataApprove(request);
2724
+ case 'pri(metadata.get)':
2725
+ return this.metadataGet(request);
2726
+ case 'pri(metadata.list)':
2727
+ return this.metadataList();
2728
+ case 'pri(metadata.reject)':
2729
+ return this.metadataReject(request);
2730
+ case 'pri(metadata.requests)':
2731
+ return this.metadataSubscribe(id, port);
2732
+ case 'pri(derivation.create)':
2733
+ return this.derivationCreate(request);
2734
+ case 'pri(derivation.validate)':
2735
+ return this.derivationValidate(request);
2736
+ case 'pri(json.restore)':
2737
+ return this.jsonRestore(request);
2738
+ case 'pri(json.batchRestore)':
2739
+ return this.batchRestore(request);
2740
+ case 'pri(json.account.info)':
2741
+ return this.jsonGetAccountInfo(request);
2742
+ case 'pri(seed.create)':
2743
+ return this.seedCreate(request);
2744
+ case 'pri(seed.validate)':
2745
+ return this.seedValidate(request);
2746
+ case 'pri(settings.notification)':
2747
+ return this.#koniState.setNotification(request);
2748
+ case 'pri(signing.approve.signature)':
2749
+ return this.signingApproveSignature(request);
2750
+ case 'pri(signing.cancel)':
2751
+ return this.signingCancel(request);
2752
+ case 'pri(signing.requests)':
2753
+ return this.signingSubscribe(id, port);
2754
+ case 'pri(window.open)':
2755
+ return this.windowOpen(request);
2756
+
2757
+ ///
2758
+ case 'pri(authorize.changeSiteAll)':
2759
+ return this.changeAuthorizationAll(request, id, port);
2760
+ case 'pri(authorize.changeSite)':
2761
+ return this.changeAuthorization(request, id, port);
2762
+ case 'pri(authorize.changeSitePerAccount)':
2763
+ return this.changeAuthorizationPerAcc(request, id, port);
2764
+ case 'pri(authorize.changeSitePerSite)':
2765
+ return this.changeAuthorizationPerSite(request);
2766
+ case 'pri(authorize.changeSiteBlock)':
2767
+ return this.changeAuthorizationBlock(request);
2768
+ case 'pri(authorize.forgetSite)':
2769
+ return this.forgetSite(request, id, port);
2770
+ case 'pri(authorize.forgetAllSite)':
2771
+ return this.forgetAllSite(id, port);
2772
+ case 'pri(authorize.approveV2)':
2773
+ return this.authorizeApproveV2(request);
2774
+ case 'pri(authorize.rejectV2)':
2775
+ return this.authorizeRejectV2(request);
2776
+ case 'pri(authorize.cancelV2)':
2777
+ return this.authorizeCancelV2(request);
2778
+ case 'pri(authorize.requestsV2)':
2779
+ return this.authorizeSubscribeV2(id, port);
2780
+ case 'pri(authorize.listV2)':
2781
+ return this.getAuthListV2();
2782
+ case 'pri(authorize.toggle)':
2783
+ return this.toggleAuthorization2(request);
2784
+ case 'pri(accounts.create.suriV2)':
2785
+ return await this.accountsCreateSuriV2(request);
2786
+ case 'pri(accounts.forget)':
2787
+ return await this.accountsForgetOverride(request);
2788
+ case 'pri(accounts.create.externalV2)':
2789
+ return await this.accountsCreateExternalV2(request);
2790
+ case 'pri(accounts.create.hardwareV2)':
2791
+ return await this.accountsCreateHardwareV2(request);
2792
+ case 'pri(accounts.create.hardwareMultiple)':
2793
+ return await this.accountsCreateHardwareMultiple(request);
2794
+ case 'pri(accounts.create.withSecret)':
2795
+ return await this.accountsCreateWithSecret(request);
2796
+ case 'pri(seed.createV2)':
2797
+ return this.seedCreateV2(request);
2798
+ case 'pri(seed.validateV2)':
2799
+ return this.seedValidateV2(request);
2800
+ case 'pri(privateKey.validateV2)':
2801
+ return this.metamaskPrivateKeyValidateV2(request);
2802
+ case 'pri(accounts.exportPrivateKey)':
2803
+ return this.accountExportPrivateKey(request);
2804
+ case 'pri(accounts.checkPublicAndSecretKey)':
2805
+ return this.checkPublicAndSecretKey(request);
2806
+ case 'pri(accounts.subscribeWithCurrentAddress)':
2807
+ return await this.accountsGetAllWithCurrentAddress(id, port);
2808
+ case 'pri(accounts.subscribeAccountsInputAddress)':
2809
+ return this.accountsGetAll(id, port);
2810
+ case 'pri(accounts.saveRecent)':
2811
+ return this.saveRecentAccountId(request);
2812
+ case 'pri(accounts.triggerSubscription)':
2813
+ return this.triggerAccountsSubscription();
2814
+ case 'pri(currentAccount.saveAddress)':
2815
+ return this.saveCurrentAccountAddress(request, id, port);
2816
+ case 'pri(accounts.updateCurrentAddress)':
2817
+ return this.updateCurrentAccountAddress(request);
2818
+ case 'pri(settings.changeBalancesVisibility)':
2819
+ return this.toggleBalancesVisibility(id, port);
2820
+ case 'pri(settings.subscribe)':
2821
+ return await this.subscribeSettings(id, port);
2822
+ case 'pri(settings.saveAccountAllLogo)':
2823
+ return this.saveAccountAllLogo(request, id, port);
2824
+ case 'pri(settings.saveTheme)':
2825
+ return this.saveTheme(request, id, port);
2826
+ case 'pri(settings.saveBrowserConfirmationType)':
2827
+ return this.saveBrowserConfirmationType(request, id, port);
2828
+ case 'pri(price.getPrice)':
2829
+ return await this.getPrice();
2830
+ case 'pri(price.getSubscription)':
2831
+ return await this.subscribePrice(id, port);
2832
+ case 'pri(balance.getBalance)':
2833
+ return this.getBalance();
2834
+ case 'pri(balance.getSubscription)':
2835
+ return this.subscribeBalance(id, port);
2836
+ case 'pri(crowdloan.getCrowdloan)':
2837
+ return this.getCrowdloan();
2838
+ case 'pri(crowdloan.getSubscription)':
2839
+ return this.subscribeCrowdloan(id, port);
2840
+ case 'pri(derivation.createV2)':
2841
+ return this.derivationCreateV2(request);
2842
+ case 'pri(json.restoreV2)':
2843
+ return this.jsonRestoreV2(request);
2844
+ case 'pri(json.batchRestoreV2)':
2845
+ return this.batchRestoreV2(request);
2846
+ case 'pri(nft.getNft)':
2847
+ return await this.getNft();
2848
+ case 'pri(nft.getSubscription)':
2849
+ return await this.subscribeNft(id, port);
2850
+ case 'pri(nftCollection.getNftCollection)':
2851
+ return await this.getNftCollection();
2852
+ case 'pri(nftCollection.getSubscription)':
2853
+ return await this.subscribeNftCollection(id, port);
2854
+ case 'pri(staking.getStaking)':
2855
+ return this.getStaking();
2856
+ case 'pri(staking.getSubscription)':
2857
+ return await this.subscribeStaking(id, port);
2858
+ case 'pri(stakingReward.getStakingReward)':
2859
+ return this.getStakingReward();
2860
+ case 'pri(stakingReward.getSubscription)':
2861
+ return this.subscribeStakingReward(id, port);
2862
+ case 'pri(transaction.history.getSubscription)':
2863
+ return await this.subscribeHistory(id, port);
2864
+
2865
+ // ChainService
2866
+ case 'pri(chainService.subscribeChainInfoMap)':
2867
+ return this.subscribeChainInfoMap(id, port);
2868
+ case 'pri(chainService.subscribeChainStateMap)':
2869
+ return this.subscribeChainStateMap(id, port);
2870
+ case 'pri(chainService.getSupportedContractTypes)':
2871
+ return this.getSupportedSmartContractTypes();
2872
+ case 'pri(chainService.enableChain)':
2873
+ return this.enableChain(request);
2874
+ case 'pri(chainService.disableChain)':
2875
+ return this.disableChain(request);
2876
+ case 'pri(chainService.removeChain)':
2877
+ return this.removeCustomChain(request);
2878
+ case 'pri(chainService.validateCustomChain)':
2879
+ return await this.validateNetwork(request);
2880
+ case 'pri(chainService.upsertChain)':
2881
+ return this.upsertChain(request);
2882
+ case 'pri(chainService.resetDefaultChains)':
2883
+ return this.resetDefaultNetwork();
2884
+ case 'pri(chainService.enableChains)':
2885
+ return this.enableChains(request);
2886
+ case 'pri(chainService.subscribeAssetRegistry)':
2887
+ return this.subscribeAssetRegistry(id, port);
2888
+ case 'pri(chainService.subscribeMultiChainAssetMap)':
2889
+ return this.subscribeMultiChainAssetMap(id, port);
2890
+ case 'pri(chainService.upsertCustomAsset)':
2891
+ return this.upsertCustomToken(request);
2892
+ case 'pri(chainService.deleteCustomAsset)':
2893
+ return this.deleteCustomAsset(request);
2894
+ case 'pri(chainService.validateCustomAsset)':
2895
+ return await this.validateCustomAsset(request);
2896
+ case 'pri(assetSetting.getSubscription)':
2897
+ return this.subscribeAssetSetting(id, port);
2898
+ case 'pri(assetSetting.update)':
2899
+ return this.updateAssetSetting(request);
2900
+ case 'pri(transfer.checkReferenceCount)':
2901
+ return await this.transferCheckReferenceCount(request);
2902
+ case 'pri(transfer.checkSupporting)':
2903
+ return await this.transferCheckSupporting(request);
2904
+ case 'pri(transfer.getExistentialDeposit)':
2905
+ return this.transferGetExistentialDeposit(request);
2906
+ case 'pri(freeBalance.subscribe)':
2907
+ return this.subscribeAddressFreeBalance(request, id, port);
2908
+ case 'pri(subscription.cancel)':
2909
+ return this.cancelSubscription(request);
2910
+ case 'pri(chainService.recoverSubstrateApi)':
2911
+ return this.recoverDotSamaApi(request);
2912
+ case 'pri(accounts.get.meta)':
2913
+ return this.getAccountMeta(request);
2914
+
2915
+ /// Nft
2916
+ case 'pri(nft.forceUpdate)':
2917
+ return this.forceUpdateNftState(request);
2918
+ case 'pri(nftTransfer.getNftTransfer)':
2919
+ return this.getNftTransfer();
2920
+ case 'pri(nftTransfer.getSubscription)':
2921
+ return this.subscribeNftTransfer(id, port);
2922
+ case 'pri(nftTransfer.setNftTransfer)':
2923
+ return this.setNftTransfer(request);
2924
+
2925
+ // Send NFT
2926
+ case 'pri(evmNft.submitTransaction)':
2927
+ return this.evmNftSubmitTransaction(request);
2928
+ case 'pri(substrateNft.submitTransaction)':
2929
+ return this.substrateNftSubmitTransaction(request);
2930
+
2931
+ /// Transfer
2932
+ case 'pri(accounts.transfer)':
2933
+ return await this.makeTransfer(request);
2934
+ case 'pri(accounts.crossChainTransfer)':
2935
+ return await this.makeCrossChainTransfer(request);
2936
+
2937
+ /// Sign QR
2938
+ case 'pri(qr.transaction.parse.substrate)':
2939
+ return this.parseSubstrateTransaction(request);
2940
+ case 'pri(qr.transaction.parse.evm)':
2941
+ return await this.parseEVMRLP(request);
2942
+ case 'pri(qr.sign.substrate)':
2943
+ return this.qrSignSubstrate(request);
2944
+ case 'pri(qr.sign.evm)':
2945
+ return await this.qrSignEVM(request);
2946
+
2947
+ /// External account request
2948
+ case 'pri(account.external.reject)':
2949
+ return this.rejectExternalRequest(request);
2950
+ case 'pri(account.external.resolve)':
2951
+ return this.resolveQrTransfer(request);
2952
+ case 'pri(accounts.tie)':
2953
+ return this.accountsTie2(request);
2954
+ case 'pri(confirmations.subscribe)':
2955
+ return this.subscribeConfirmations(id, port);
2956
+ case 'pri(confirmations.complete)':
2957
+ return await this.completeConfirmation(request);
2958
+
2959
+ /// Stake
2960
+ case 'pri(bonding.getBondingOptions)':
2961
+ return await this.getBondingOptions(request);
2962
+ case 'pri(bonding.getNominationPoolOptions)':
2963
+ return await this.getNominationPoolOptions(request);
2964
+ case 'pri(bonding.subscribeChainStakingMetadata)':
2965
+ return await this.subscribeChainStakingMetadata(id, port);
2966
+ case 'pri(bonding.subscribeNominatorMetadata)':
2967
+ return await this.subscribeStakingNominatorMetadata(id, port);
2968
+ case 'pri(bonding.submitBondingTransaction)':
2969
+ return await this.submitBonding(request);
2970
+ case 'pri(unbonding.submitTransaction)':
2971
+ return await this.submitUnbonding(request);
2972
+ case 'pri(unbonding.submitWithdrawal)':
2973
+ return await this.submitStakeWithdrawal(request);
2974
+ case 'pri(staking.submitClaimReward)':
2975
+ return await this.submitStakeClaimReward(request);
2976
+ case 'pri(staking.submitCancelWithdrawal)':
2977
+ return await this.submitCancelStakeWithdrawal(request);
2978
+ case 'pri(staking.submitTuringCompound)':
2979
+ return await this.submitTuringStakeCompounding(request);
2980
+ case 'pri(staking.submitTuringCancelCompound)':
2981
+ return await this.submitTuringCancelStakeCompound(request);
2982
+ case 'pri(bonding.nominationPool.submitBonding)':
2983
+ return await this.submitPoolingBonding(request);
2984
+ case 'pri(bonding.nominationPool.submitUnbonding)':
2985
+ return await this.submitPoolingUnbonding(request);
2986
+ case 'pri(bonding.nominationPool.submitWithdrawal)':
2987
+ return await this.submitPoolingWithdrawal(request);
2988
+
2989
+ // EVM Transaction
2990
+ case 'pri(evm.transaction.parse.input)':
2991
+ return await this.parseContractInput(request);
2992
+
2993
+ // Auth Url subscribe
2994
+ case 'pri(authorize.subscribe)':
2995
+ return await this.subscribeAuthUrls(id, port);
2996
+ case 'pri(wasmNft.getTransaction)':
2997
+ return await this.wasmNftGetTransaction(request);
2998
+
2999
+ /// Keyring state
3000
+ case 'pri(keyring.subscribe)':
3001
+ return this.keyringStateSubscribe(id, port);
3002
+ case 'pri(keyring.change)':
3003
+ return this.keyringChangeMasterPassword(request);
3004
+ case 'pri(keyring.migrate)':
3005
+ return this.keyringMigrateMasterPassword(request);
3006
+ case 'pri(keyring.unlock)':
3007
+ return this.keyringUnlock(request);
3008
+ case 'pri(keyring.lock)':
3009
+ return this.keyringLock();
3010
+ case 'pri(keyring.export.mnemonic)':
3011
+ return this.keyringExportMnemonic(request);
3012
+
3013
+ /// Signing external
3014
+ case 'pri(signing.approve.passwordV2)':
3015
+ return this.signingApprovePasswordV2(request);
3016
+
3017
+ /// Derive account
3018
+ case 'pri(derivation.validateV2)':
3019
+ return this.validateDerivePath(request);
3020
+ case 'pri(derivation.getList)':
3021
+ return this.getListDeriveAccounts(request);
3022
+ case 'pri(derivation.create.multiple)':
3023
+ return this.derivationCreateMultiple(request);
3024
+ case 'pri(derivation.createV3)':
3025
+ return this.derivationCreateV3(request);
3026
+
3027
+ // Transaction
3028
+ case 'pri(transactions.getOne)':
3029
+ return this.getTransaction(request);
3030
+ case 'pri(transactions.subscribe)':
3031
+ return this.subscribeTransactions(id, port);
3032
+
3033
+ // Default
3034
+ default:
3035
+ throw new Error(`Unable to handle message of type ${type}`);
3036
+ }
3037
+ }
3038
+ }