@subwallet/extension-base 0.8.4-0 → 1.0.1

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