@subwallet/extension-base 0.8.1-wr → 0.8.1-wr3

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