@subwallet/extension-base 0.8.4-0 → 1.0.2-1

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