@subwallet/extension-base 0.8.4-0 → 1.0.1

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