@subwallet/extension-base 1.2.31-0 → 1.2.33-0

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 (418) hide show
  1. package/background/KoniTypes.d.ts +78 -227
  2. package/background/KoniTypes.js +3 -40
  3. package/background/errors/SWError.d.ts +4 -7
  4. package/background/errors/SWError.js +4 -0
  5. package/background/errors/TransactionError.d.ts +2 -2
  6. package/background/errors/TransactionError.js +2 -4
  7. package/background/handlers/State.d.ts +0 -12
  8. package/background/types.d.ts +9 -134
  9. package/background/warnings/TransactionWarning.d.ts +1 -1
  10. package/background/warnings/TransactionWarning.js +5 -1
  11. package/cjs/background/KoniTypes.js +4 -44
  12. package/cjs/background/errors/SWError.js +4 -0
  13. package/cjs/background/errors/TransactionError.js +13 -15
  14. package/cjs/background/warnings/TransactionWarning.js +6 -2
  15. package/cjs/constants/environment.js +13 -0
  16. package/cjs/constants/index.js +40 -13
  17. package/cjs/constants/signing.js +23 -0
  18. package/cjs/constants/storage.js +4 -2
  19. package/cjs/core/consts.js +20 -0
  20. package/cjs/core/logic-validation/recipientAddress.js +106 -0
  21. package/cjs/core/logic-validation/request.js +11 -19
  22. package/cjs/core/logic-validation/swap.js +5 -5
  23. package/cjs/core/logic-validation/transfer.js +83 -42
  24. package/cjs/core/types.js +26 -0
  25. package/cjs/core/utils.js +113 -0
  26. package/cjs/koni/api/dotsama/crowdloan.js +1 -1
  27. package/cjs/koni/api/nft/index.js +14 -5
  28. package/cjs/koni/api/staking/bonding/paraChain.js +8 -8
  29. package/cjs/koni/api/staking/bonding/relayChain.js +9 -9
  30. package/cjs/koni/api/staking/index.js +4 -1
  31. package/cjs/koni/background/cron.js +7 -7
  32. package/cjs/koni/background/handlers/Extension.js +510 -1446
  33. package/cjs/koni/background/handlers/State.js +61 -238
  34. package/cjs/koni/background/handlers/Tabs.js +143 -107
  35. package/cjs/koni/background/subscription.js +5 -5
  36. package/cjs/packageInfo.js +1 -1
  37. package/cjs/page/Accounts.js +2 -5
  38. package/cjs/page/SubWalleEvmProvider.js +1 -1
  39. package/cjs/page/index.js +2 -1
  40. package/cjs/services/balance-service/BalanceMapImpl.js +48 -20
  41. package/cjs/services/balance-service/helpers/subscribe/index.js +27 -15
  42. package/cjs/services/balance-service/helpers/subscribe/ton/consts.js +40 -0
  43. package/cjs/services/balance-service/helpers/subscribe/ton/ton.js +120 -0
  44. package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +181 -0
  45. package/cjs/services/balance-service/index.js +25 -13
  46. package/cjs/services/balance-service/transfer/token.js +41 -24
  47. package/cjs/services/balance-service/transfer/ton-transfer.js +136 -0
  48. package/cjs/services/buy-service/index.js +5 -1
  49. package/cjs/services/chain-service/constants.js +1 -1
  50. package/cjs/services/chain-service/handler/SubstrateApi.js +1 -0
  51. package/cjs/services/chain-service/handler/TonApi.js +213 -0
  52. package/cjs/services/chain-service/handler/TonChainHandler.js +81 -0
  53. package/cjs/services/chain-service/index.js +32 -8
  54. package/cjs/services/chain-service/utils/index.js +78 -22
  55. package/cjs/services/earning-service/constants/chains.js +3 -1
  56. package/cjs/services/earning-service/handlers/base.js +2 -1
  57. package/cjs/services/earning-service/handlers/lending/base.js +8 -9
  58. package/cjs/services/earning-service/handlers/lending/interlay.js +1 -1
  59. package/cjs/services/earning-service/handlers/liquid-staking/base.js +9 -10
  60. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -1
  61. package/cjs/services/earning-service/handlers/native-staking/amplitude.js +1 -1
  62. package/cjs/services/earning-service/handlers/native-staking/astar.js +2 -2
  63. package/cjs/services/earning-service/handlers/native-staking/base-para.js +13 -13
  64. package/cjs/services/earning-service/handlers/native-staking/base.js +2 -2
  65. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +2 -2
  66. package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +15 -15
  67. package/cjs/services/earning-service/handlers/nomination-pool/index.js +14 -14
  68. package/cjs/services/earning-service/handlers/special.js +10 -10
  69. package/cjs/services/earning-service/service.js +26 -17
  70. package/cjs/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
  71. package/cjs/services/history-service/index.js +29 -11
  72. package/cjs/services/history-service/subscan-history.js +9 -21
  73. package/cjs/services/keyring-service/context/account-context.js +259 -0
  74. package/cjs/services/keyring-service/context/handlers/Base.js +20 -0
  75. package/cjs/services/keyring-service/context/handlers/Derive.js +377 -0
  76. package/cjs/services/keyring-service/context/handlers/Inject.js +75 -0
  77. package/cjs/services/keyring-service/context/handlers/Json.js +348 -0
  78. package/cjs/services/keyring-service/context/handlers/Ledger.js +165 -0
  79. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +218 -0
  80. package/cjs/services/keyring-service/context/handlers/Modify.js +258 -0
  81. package/cjs/services/keyring-service/context/handlers/Secret.js +310 -0
  82. package/cjs/services/keyring-service/context/handlers/index.js +82 -0
  83. package/cjs/services/keyring-service/context/state.js +649 -0
  84. package/cjs/services/keyring-service/context/stores/AccountProxy.js +32 -0
  85. package/cjs/services/keyring-service/context/stores/Base.js +37 -0
  86. package/cjs/services/keyring-service/context/stores/CurrentAccount.js +28 -0
  87. package/cjs/services/keyring-service/context/stores/ModifyPair.js +19 -0
  88. package/cjs/services/keyring-service/context/stores/index.js +38 -0
  89. package/cjs/services/keyring-service/index.js +20 -164
  90. package/cjs/services/migration-service/scripts/index.js +6 -4
  91. package/cjs/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
  92. package/cjs/services/migration-service/scripts/keyring/MigratePairData.js +28 -0
  93. package/cjs/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
  94. package/cjs/services/request-service/constants.js +5 -3
  95. package/cjs/services/request-service/handler/AuthRequestHandler.js +104 -57
  96. package/cjs/services/request-service/handler/EvmRequestHandler.js +3 -4
  97. package/cjs/services/request-service/handler/SubstrateRequestHandler.js +5 -11
  98. package/cjs/services/request-service/handler/TonRequestHandler.js +175 -0
  99. package/cjs/services/request-service/index.js +24 -5
  100. package/cjs/services/swap-service/handler/asset-hub/handler.js +6 -5
  101. package/cjs/services/swap-service/handler/base-handler.js +8 -8
  102. package/cjs/services/swap-service/handler/chainflip-handler.js +5 -4
  103. package/cjs/services/swap-service/handler/hydradx-handler.js +4 -3
  104. package/cjs/services/swap-service/index.js +4 -4
  105. package/cjs/services/transaction-service/helpers/index.js +6 -1
  106. package/cjs/services/transaction-service/index.js +184 -84
  107. package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
  108. package/cjs/stores/AccountProxyStore.js +18 -0
  109. package/cjs/stores/ModifyPairStore.js +18 -0
  110. package/cjs/stores/index.js +23 -2
  111. package/cjs/types/account/action/add/index.js +38 -0
  112. package/cjs/types/account/action/add/json.js +1 -0
  113. package/cjs/types/account/action/add/mnemonic.js +1 -0
  114. package/cjs/types/account/action/add/secret.js +1 -0
  115. package/cjs/types/account/action/derive.js +1 -0
  116. package/cjs/types/account/action/edit.js +1 -0
  117. package/cjs/types/account/action/export.js +1 -0
  118. package/cjs/types/account/action/index.js +71 -0
  119. package/cjs/types/account/action/subscribe.js +16 -0
  120. package/cjs/types/account/action/validate.js +1 -0
  121. package/cjs/types/account/error/common.js +40 -0
  122. package/cjs/types/account/error/derive.js +55 -0
  123. package/cjs/types/account/error/index.js +27 -0
  124. package/cjs/types/account/index.js +38 -0
  125. package/cjs/types/account/info/current.js +1 -0
  126. package/cjs/types/account/info/index.js +38 -0
  127. package/cjs/types/account/info/keyring.js +90 -0
  128. package/cjs/types/account/info/proxy.js +49 -0
  129. package/cjs/types/error.js +1 -0
  130. package/cjs/types/index.js +44 -0
  131. package/cjs/types/transaction/data.js +1 -0
  132. package/cjs/types/transaction/error.js +53 -0
  133. package/cjs/types/transaction/index.js +49 -0
  134. package/cjs/types/transaction/request.js +1 -0
  135. package/cjs/types/transaction/warning.js +14 -0
  136. package/cjs/types/yield/actions/join/validate.js +1 -16
  137. package/cjs/utils/account/analyze.js +166 -0
  138. package/cjs/utils/account/common.js +121 -0
  139. package/cjs/utils/account/derive/index.js +27 -0
  140. package/cjs/utils/account/derive/info/index.js +27 -0
  141. package/cjs/utils/account/derive/info/solo.js +246 -0
  142. package/cjs/utils/account/derive/info/unified.js +112 -0
  143. package/cjs/utils/account/derive/validate.js +177 -0
  144. package/cjs/utils/account/index.js +49 -0
  145. package/cjs/utils/account/transform.js +566 -0
  146. package/cjs/utils/auth.js +46 -0
  147. package/cjs/utils/getId.js +8 -1
  148. package/cjs/utils/index.js +48 -62
  149. package/constants/environment.d.ts +1 -0
  150. package/constants/environment.js +6 -0
  151. package/constants/index.d.ts +5 -1
  152. package/constants/index.js +5 -2
  153. package/constants/signing.d.ts +4 -0
  154. package/constants/signing.js +15 -0
  155. package/constants/storage.d.ts +1 -0
  156. package/constants/storage.js +2 -1
  157. package/core/consts.d.ts +1 -0
  158. package/core/consts.js +13 -0
  159. package/core/logic-validation/recipientAddress.d.ts +2 -0
  160. package/core/logic-validation/recipientAddress.js +100 -0
  161. package/core/logic-validation/request.js +10 -18
  162. package/core/logic-validation/swap.js +1 -1
  163. package/core/logic-validation/transfer.d.ts +3 -2
  164. package/core/logic-validation/transfer.js +50 -10
  165. package/core/types.d.ts +26 -0
  166. package/core/types.js +19 -0
  167. package/core/utils.d.ts +10 -0
  168. package/core/utils.js +105 -0
  169. package/koni/api/dotsama/crowdloan.js +1 -1
  170. package/koni/api/nft/index.js +14 -5
  171. package/koni/api/staking/bonding/paraChain.js +2 -2
  172. package/koni/api/staking/bonding/relayChain.js +2 -2
  173. package/koni/api/staking/index.js +4 -1
  174. package/koni/background/cron.js +7 -7
  175. package/koni/background/handlers/Extension.d.ts +26 -35
  176. package/koni/background/handlers/Extension.js +337 -1242
  177. package/koni/background/handlers/State.d.ts +12 -19
  178. package/koni/background/handlers/State.js +57 -231
  179. package/koni/background/handlers/Tabs.d.ts +2 -3
  180. package/koni/background/handlers/Tabs.js +105 -61
  181. package/koni/background/subscription.js +5 -5
  182. package/package.json +352 -53
  183. package/packageInfo.js +1 -1
  184. package/page/Accounts.js +2 -5
  185. package/page/SubWalleEvmProvider.js +1 -1
  186. package/page/index.js +2 -1
  187. package/services/balance-service/BalanceMapImpl.d.ts +6 -4
  188. package/services/balance-service/BalanceMapImpl.js +44 -18
  189. package/services/balance-service/helpers/subscribe/index.d.ts +3 -4
  190. package/services/balance-service/helpers/subscribe/index.js +29 -17
  191. package/services/balance-service/helpers/subscribe/ton/consts.d.ts +18 -0
  192. package/services/balance-service/helpers/subscribe/ton/consts.js +28 -0
  193. package/services/balance-service/helpers/subscribe/ton/ton.d.ts +3 -0
  194. package/services/balance-service/helpers/subscribe/ton/ton.js +111 -0
  195. package/services/balance-service/helpers/subscribe/ton/types.d.ts +26 -0
  196. package/services/balance-service/helpers/subscribe/ton/utils.d.ts +32 -0
  197. package/services/balance-service/helpers/subscribe/ton/utils.js +159 -0
  198. package/services/balance-service/index.js +25 -13
  199. package/services/balance-service/transfer/token.d.ts +2 -2
  200. package/services/balance-service/transfer/token.js +18 -1
  201. package/services/balance-service/transfer/ton-transfer.d.ts +25 -0
  202. package/services/balance-service/transfer/ton-transfer.js +127 -0
  203. package/services/buy-service/index.js +5 -1
  204. package/services/buy-service/types.d.ts +2 -2
  205. package/services/chain-service/constants.js +1 -1
  206. package/services/chain-service/handler/SubstrateApi.js +1 -0
  207. package/services/chain-service/handler/TonApi.d.ts +52 -0
  208. package/services/chain-service/handler/TonApi.js +204 -0
  209. package/services/chain-service/handler/TonChainHandler.d.ts +17 -0
  210. package/services/chain-service/handler/TonChainHandler.js +73 -0
  211. package/services/chain-service/index.d.ts +5 -1
  212. package/services/chain-service/index.js +32 -8
  213. package/services/chain-service/types.d.ts +24 -0
  214. package/services/chain-service/utils/index.d.ts +10 -2
  215. package/services/chain-service/utils/index.js +59 -18
  216. package/services/earning-service/constants/chains.d.ts +1 -0
  217. package/services/earning-service/constants/chains.js +1 -0
  218. package/services/earning-service/handlers/base.js +3 -2
  219. package/services/earning-service/handlers/lending/base.js +1 -2
  220. package/services/earning-service/handlers/lending/interlay.js +2 -2
  221. package/services/earning-service/handlers/liquid-staking/base.js +1 -2
  222. package/services/earning-service/handlers/liquid-staking/stella-swap.js +2 -2
  223. package/services/earning-service/handlers/native-staking/amplitude.js +2 -2
  224. package/services/earning-service/handlers/native-staking/astar.js +2 -2
  225. package/services/earning-service/handlers/native-staking/base-para.js +2 -2
  226. package/services/earning-service/handlers/native-staking/base.js +2 -2
  227. package/services/earning-service/handlers/native-staking/para-chain.js +2 -2
  228. package/services/earning-service/handlers/native-staking/relay-chain.js +2 -2
  229. package/services/earning-service/handlers/nomination-pool/index.js +2 -2
  230. package/services/earning-service/handlers/special.js +2 -2
  231. package/services/earning-service/service.js +18 -9
  232. package/services/event-service/types.d.ts +3 -1
  233. package/services/history-service/helpers/subscan-extrinsic-parser-helper.js +1 -1
  234. package/services/history-service/index.d.ts +4 -1
  235. package/services/history-service/index.js +29 -11
  236. package/services/history-service/subscan-history.js +8 -20
  237. package/services/keyring-service/context/account-context.d.ts +87 -0
  238. package/services/keyring-service/context/account-context.js +250 -0
  239. package/services/keyring-service/context/handlers/Base.d.ts +11 -0
  240. package/services/keyring-service/context/handlers/Base.js +13 -0
  241. package/services/keyring-service/context/handlers/Derive.d.ts +29 -0
  242. package/services/keyring-service/context/handlers/Derive.js +365 -0
  243. package/services/keyring-service/context/handlers/Inject.d.ts +11 -0
  244. package/services/keyring-service/context/handlers/Inject.js +69 -0
  245. package/services/keyring-service/context/handlers/Json.d.ts +18 -0
  246. package/services/keyring-service/context/handlers/Json.js +328 -0
  247. package/services/keyring-service/context/handlers/Ledger.d.ts +11 -0
  248. package/services/keyring-service/context/handlers/Ledger.js +158 -0
  249. package/services/keyring-service/context/handlers/Mnemonic.d.ts +15 -0
  250. package/services/keyring-service/context/handlers/Mnemonic.js +206 -0
  251. package/services/keyring-service/context/handlers/Modify.d.ts +16 -0
  252. package/services/keyring-service/context/handlers/Modify.js +250 -0
  253. package/services/keyring-service/context/handlers/Secret.d.ts +16 -0
  254. package/services/keyring-service/context/handlers/Secret.js +299 -0
  255. package/services/keyring-service/context/handlers/index.d.ts +7 -0
  256. package/services/keyring-service/context/handlers/index.js +10 -0
  257. package/services/keyring-service/context/state.d.ts +92 -0
  258. package/services/keyring-service/context/state.js +629 -0
  259. package/services/keyring-service/context/stores/AccountProxy.d.ts +13 -0
  260. package/services/keyring-service/context/stores/AccountProxy.js +25 -0
  261. package/services/keyring-service/context/stores/Base.d.ts +22 -0
  262. package/services/keyring-service/context/stores/Base.js +30 -0
  263. package/services/keyring-service/context/stores/CurrentAccount.d.ts +15 -0
  264. package/services/keyring-service/context/stores/CurrentAccount.js +21 -0
  265. package/services/keyring-service/context/stores/ModifyPair.d.ts +10 -0
  266. package/services/keyring-service/context/stores/ModifyPair.js +12 -0
  267. package/services/keyring-service/context/stores/index.d.ts +3 -0
  268. package/services/keyring-service/context/stores/index.js +6 -0
  269. package/services/keyring-service/index.d.ts +10 -22
  270. package/services/keyring-service/index.js +20 -161
  271. package/services/migration-service/scripts/index.js +6 -4
  272. package/services/migration-service/scripts/{MigrateLedgerAccountV2.d.ts → keyring/MigrateLedgerAccountV2.d.ts} +1 -1
  273. package/services/migration-service/scripts/{MigrateLedgerAccountV2.js → keyring/MigrateLedgerAccountV2.js} +1 -1
  274. package/services/migration-service/scripts/keyring/MigratePairData.d.ts +4 -0
  275. package/services/migration-service/scripts/keyring/MigratePairData.js +20 -0
  276. package/services/migration-service/scripts/{MigrateRemoveGenesisHash.js → keyring/MigrateRemoveGenesisHash.js} +1 -1
  277. package/services/mkt-campaign-service/types.d.ts +4 -0
  278. package/services/request-service/constants.d.ts +1 -1
  279. package/services/request-service/constants.js +2 -1
  280. package/services/request-service/handler/AuthRequestHandler.d.ts +1 -0
  281. package/services/request-service/handler/AuthRequestHandler.js +93 -45
  282. package/services/request-service/handler/EvmRequestHandler.js +3 -4
  283. package/services/request-service/handler/SubstrateRequestHandler.d.ts +2 -2
  284. package/services/request-service/handler/SubstrateRequestHandler.js +5 -11
  285. package/services/request-service/handler/TonRequestHandler.d.ts +17 -0
  286. package/services/request-service/handler/TonRequestHandler.js +168 -0
  287. package/services/request-service/index.d.ts +8 -3
  288. package/services/request-service/index.js +23 -5
  289. package/services/request-service/types.d.ts +6 -3
  290. package/services/swap-service/handler/asset-hub/handler.d.ts +1 -1
  291. package/services/swap-service/handler/asset-hub/handler.js +2 -1
  292. package/services/swap-service/handler/base-handler.js +1 -1
  293. package/services/swap-service/handler/chainflip-handler.d.ts +1 -1
  294. package/services/swap-service/handler/chainflip-handler.js +4 -3
  295. package/services/swap-service/handler/hydradx-handler.d.ts +1 -1
  296. package/services/swap-service/handler/hydradx-handler.js +2 -1
  297. package/services/swap-service/index.js +1 -1
  298. package/services/transaction-service/helpers/index.d.ts +2 -0
  299. package/services/transaction-service/helpers/index.js +4 -0
  300. package/services/transaction-service/index.d.ts +1 -0
  301. package/services/transaction-service/index.js +114 -17
  302. package/services/transaction-service/types.d.ts +4 -2
  303. package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +2 -10
  304. package/stores/AccountProxyStore.d.ts +5 -0
  305. package/stores/AccountProxyStore.js +10 -0
  306. package/stores/Authorize.d.ts +1 -1
  307. package/stores/CurrentAccountStore.d.ts +1 -1
  308. package/stores/ModifyPairStore.d.ts +5 -0
  309. package/stores/ModifyPairStore.js +10 -0
  310. package/stores/index.d.ts +4 -1
  311. package/stores/index.js +5 -2
  312. package/types/account/action/add/index.d.ts +3 -0
  313. package/types/account/action/add/index.js +6 -0
  314. package/types/account/action/add/json.d.ts +29 -0
  315. package/types/account/action/add/json.js +1 -0
  316. package/types/account/action/add/mnemonic.d.ts +77 -0
  317. package/types/account/action/add/mnemonic.js +1 -0
  318. package/types/account/action/add/secret.d.ts +55 -0
  319. package/types/account/action/add/secret.js +1 -0
  320. package/types/account/action/derive.d.ts +77 -0
  321. package/types/account/action/derive.js +1 -0
  322. package/types/account/action/edit.d.ts +31 -0
  323. package/types/account/action/edit.js +1 -0
  324. package/types/account/action/export.d.ts +15 -0
  325. package/types/account/action/export.js +1 -0
  326. package/types/account/action/index.d.ts +6 -0
  327. package/types/account/action/index.js +9 -0
  328. package/types/account/action/subscribe.d.ts +22 -0
  329. package/types/account/action/subscribe.js +10 -0
  330. package/types/account/action/validate.d.ts +17 -0
  331. package/types/account/action/validate.js +1 -0
  332. package/types/account/error/common.d.ts +10 -0
  333. package/types/account/error/common.js +33 -0
  334. package/types/account/error/derive.d.ts +13 -0
  335. package/types/account/error/derive.js +48 -0
  336. package/types/account/error/index.d.ts +2 -0
  337. package/types/account/error/index.js +5 -0
  338. package/types/account/index.d.ts +3 -0
  339. package/types/account/index.js +6 -0
  340. package/types/account/info/current.d.ts +10 -0
  341. package/types/account/info/current.js +1 -0
  342. package/types/account/info/index.d.ts +3 -0
  343. package/types/account/info/index.js +6 -0
  344. package/types/account/info/keyring.d.ts +161 -0
  345. package/types/account/info/keyring.js +88 -0
  346. package/types/account/info/proxy.d.ts +73 -0
  347. package/types/account/info/proxy.js +46 -0
  348. package/types/balance/index.d.ts +4 -1
  349. package/types/buy.d.ts +3 -1
  350. package/types/error.d.ts +8 -0
  351. package/types/error.js +1 -0
  352. package/types/index.d.ts +4 -0
  353. package/types/index.js +5 -1
  354. package/types/transaction/data.d.ts +17 -0
  355. package/types/transaction/data.js +1 -0
  356. package/types/transaction/error.d.ts +39 -0
  357. package/types/transaction/error.js +44 -0
  358. package/types/transaction/index.d.ts +4 -0
  359. package/types/transaction/index.js +7 -0
  360. package/types/transaction/request.d.ts +24 -0
  361. package/types/transaction/request.js +1 -0
  362. package/types/transaction/warning.d.ts +5 -0
  363. package/types/transaction/warning.js +8 -0
  364. package/types/yield/actions/join/submit.d.ts +2 -2
  365. package/types/yield/actions/join/validate.d.ts +1 -6
  366. package/types/yield/actions/join/validate.js +1 -10
  367. package/types/yield/actions/others.d.ts +1 -1
  368. package/utils/account/analyze.d.ts +4 -0
  369. package/utils/account/analyze.js +159 -0
  370. package/utils/account/common.d.ts +16 -0
  371. package/utils/account/common.js +104 -0
  372. package/utils/account/derive/index.d.ts +2 -0
  373. package/utils/account/derive/index.js +5 -0
  374. package/utils/account/derive/info/index.d.ts +2 -0
  375. package/utils/account/derive/info/index.js +5 -0
  376. package/utils/account/derive/info/solo.d.ts +11 -0
  377. package/utils/account/derive/info/solo.js +230 -0
  378. package/utils/account/derive/info/unified.d.ts +7 -0
  379. package/utils/account/derive/info/unified.js +102 -0
  380. package/utils/account/derive/validate.d.ts +8 -0
  381. package/utils/account/derive/validate.js +165 -0
  382. package/utils/account/index.d.ts +4 -0
  383. package/utils/account/index.js +7 -0
  384. package/utils/account/transform.d.ts +41 -0
  385. package/utils/account/transform.js +533 -0
  386. package/utils/auth.d.ts +2 -0
  387. package/utils/auth.js +39 -0
  388. package/utils/canDerive.d.ts +1 -1
  389. package/utils/eth/mergeTransactionAndSignature.d.ts +1 -1
  390. package/utils/getId.d.ts +1 -0
  391. package/utils/getId.js +3 -1
  392. package/utils/index.d.ts +12 -5
  393. package/utils/index.js +28 -47
  394. package/cjs/signers/substrates/KeyringSigner.js +0 -35
  395. package/cjs/signers/substrates/LedgerSigner.js +0 -44
  396. package/cjs/signers/substrates/QrSigner.js +0 -63
  397. package/cjs/signers/types.js +0 -15
  398. package/cjs/signers/web3/QrSigner.js +0 -67
  399. package/cjs/utils/account.js +0 -34
  400. package/signers/substrates/KeyringSigner.d.ts +0 -13
  401. package/signers/substrates/KeyringSigner.js +0 -27
  402. package/signers/substrates/LedgerSigner.d.ts +0 -13
  403. package/signers/substrates/LedgerSigner.js +0 -37
  404. package/signers/substrates/QrSigner.d.ts +0 -20
  405. package/signers/substrates/QrSigner.js +0 -55
  406. package/signers/types.d.ts +0 -34
  407. package/signers/types.js +0 -9
  408. package/signers/web3/QrSigner.d.ts +0 -18
  409. package/signers/web3/QrSigner.js +0 -59
  410. package/types/transaction.d.ts +0 -3
  411. package/utils/account.d.ts +0 -5
  412. package/utils/account.js +0 -24
  413. /package/cjs/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
  414. /package/cjs/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
  415. /package/{types/transaction.js → services/balance-service/helpers/subscribe/ton/types.js} +0 -0
  416. /package/services/migration-service/scripts/{MigrateLedgerAccount.d.ts → keyring/MigrateLedgerAccount.d.ts} +0 -0
  417. /package/services/migration-service/scripts/{MigrateLedgerAccount.js → keyring/MigrateLedgerAccount.js} +0 -0
  418. /package/services/migration-service/scripts/{MigrateRemoveGenesisHash.d.ts → keyring/MigrateRemoveGenesisHash.d.ts} +0 -0
@@ -0,0 +1,69 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
+ import { keyring } from '@subwallet/ui-keyring';
6
+ import { stringShorten } from '@polkadot/util';
7
+ import { AccountBaseHandler } from "./Base.js";
8
+
9
+ /**
10
+ * @class AccountInjectHandler
11
+ * @extends AccountBaseHandler
12
+ * @description Handler for account inject actions
13
+ * */
14
+ export class AccountInjectHandler extends AccountBaseHandler {
15
+ /* Inject */
16
+
17
+ addInjectAccounts(accounts) {
18
+ keyring.addInjects(accounts.map(account => {
19
+ const name = account.meta.name || stringShorten(account.address);
20
+
21
+ // TODO: Add if need
22
+ // name = name.concat(' (', account.meta.source, ')');
23
+
24
+ return {
25
+ ...account,
26
+ meta: {
27
+ ...account.meta,
28
+ name: name
29
+ }
30
+ };
31
+ }));
32
+ const currentAddress = this.state.currentAccount.proxyId;
33
+ const afterAccounts = {};
34
+ Object.keys(this.state.accounts).forEach(adr => {
35
+ afterAccounts[adr] = true;
36
+ });
37
+ accounts.forEach(value => {
38
+ afterAccounts[value.address] = true;
39
+ });
40
+ if (Object.keys(afterAccounts).length === 1) {
41
+ this.state.saveCurrentAccountProxyId(Object.keys(afterAccounts)[0]);
42
+ } else if (Object.keys(afterAccounts).indexOf(currentAddress) === -1) {
43
+ this.state.saveCurrentAccountProxyId(ALL_ACCOUNT_KEY);
44
+ }
45
+ if (!this.state.injected) {
46
+ this.parentService.eventInjectReady();
47
+ this.state.setInjected(true);
48
+ }
49
+ }
50
+ removeInjectAccounts(_addresses) {
51
+ const addresses = _addresses.map(address => {
52
+ try {
53
+ return keyring.getPair(address).address;
54
+ } catch (error) {
55
+ return address;
56
+ }
57
+ });
58
+ const currentAddress = this.state.currentAccount.proxyId;
59
+ const afterAccounts = Object.keys(this.state.accounts).filter(address => addresses.indexOf(address) < 0);
60
+ if (afterAccounts.length === 1) {
61
+ this.state.saveCurrentAccountProxyId(afterAccounts[0]);
62
+ } else if (addresses.indexOf(currentAddress) === -1) {
63
+ this.state.saveCurrentAccountProxyId(ALL_ACCOUNT_KEY);
64
+ }
65
+ keyring.removeInjects(addresses);
66
+ }
67
+
68
+ /* Inject */
69
+ }
@@ -0,0 +1,18 @@
1
+ import { RequestAccountBatchExportV2, RequestBatchJsonGetAccountInfo, RequestBatchRestoreV2, RequestJsonGetAccountInfo, RequestJsonRestoreV2, ResponseAccountBatchExportV2, ResponseBatchJsonGetAccountInfo, ResponseJsonGetAccountInfo } from '@subwallet/extension-base/types';
2
+ import { AccountBaseHandler } from './Base';
3
+ /**
4
+ * @class AccountJsonHandler
5
+ * @extends AccountBaseHandler
6
+ * @description Handler for account's JSON
7
+ * */
8
+ export declare class AccountJsonHandler extends AccountBaseHandler {
9
+ private decodeAddress;
10
+ private encodeAddress;
11
+ private validatePassword;
12
+ parseInfoSingleJson({ json, password }: RequestJsonGetAccountInfo): ResponseJsonGetAccountInfo;
13
+ jsonRestoreV2({ address, file, isAllowed, password, withMasterPassword }: RequestJsonRestoreV2, onDone: VoidFunction): Promise<string[]>;
14
+ private validatedAccountsPassword;
15
+ parseInfoMultiJson({ json, password }: RequestBatchJsonGetAccountInfo): ResponseBatchJsonGetAccountInfo;
16
+ batchRestoreV2({ file, isAllowed, password, proxyIds: _proxyIds }: RequestBatchRestoreV2): Promise<string[]>;
17
+ batchExportV2(request: RequestAccountBatchExportV2): Promise<ResponseAccountBatchExportV2>;
18
+ }
@@ -0,0 +1,328 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
+ import { combineAccountsWithKeyPair, convertAccountProxyType, createPromiseHandler, transformAccount } from '@subwallet/extension-base/utils';
6
+ import { generateRandomString } from '@subwallet/extension-base/utils/getId';
7
+ import { createPair } from '@subwallet/keyring';
8
+ import { keyring } from '@subwallet/ui-keyring';
9
+ import { t } from 'i18next';
10
+ import { assert, hexToU8a, isHex, u8aToString } from '@polkadot/util';
11
+ import { base64Decode, jsonDecrypt } from '@polkadot/util-crypto';
12
+ import { AccountBaseHandler } from "./Base.js";
13
+
14
+ /**
15
+ * @class AccountJsonHandler
16
+ * @extends AccountBaseHandler
17
+ * @description Handler for account's JSON
18
+ * */
19
+ export class AccountJsonHandler extends AccountBaseHandler {
20
+ decodeAddress = (key, ignoreChecksum, ss58Format) => {
21
+ return keyring.decodeAddress(key, ignoreChecksum, ss58Format);
22
+ };
23
+ encodeAddress = (key, ss58Format) => {
24
+ return keyring.encodeAddress(key, ss58Format);
25
+ };
26
+ validatePassword(json, password) {
27
+ const cryptoType = Array.isArray(json.encoding.content) ? json.encoding.content[1] : 'ed25519';
28
+ const encType = Array.isArray(json.encoding.type) ? json.encoding.type : [json.encoding.type];
29
+ const pair = createPair({
30
+ toSS58: this.encodeAddress,
31
+ type: cryptoType
32
+ }, {
33
+ publicKey: this.decodeAddress(json.address, true)
34
+ }, json.meta, isHex(json.encoded) ? hexToU8a(json.encoded) : base64Decode(json.encoded), encType);
35
+
36
+ // unlock then lock (locking cleans secretKey, so needs to be last)
37
+ try {
38
+ pair.decodePkcs8(password);
39
+ pair.lock();
40
+ return true;
41
+ } catch (e) {
42
+ console.error(e);
43
+ return false;
44
+ }
45
+ }
46
+ parseInfoSingleJson({
47
+ json,
48
+ password
49
+ }) {
50
+ const isPasswordValidated = this.validatePassword(json, password);
51
+ if (isPasswordValidated) {
52
+ try {
53
+ const {
54
+ address,
55
+ meta,
56
+ type
57
+ } = keyring.createFromJson(json);
58
+ const {
59
+ name
60
+ } = meta;
61
+ const account = transformAccount(address, type, meta);
62
+ const accountExists = this.state.checkAddressExists([address]);
63
+ const nameExists = this.state.checkNameExists(name);
64
+ // Note: Show accountName of account exists to support user to know which account is existed
65
+ const accountName = accountExists ? accountExists.name : account.name || account.address;
66
+ const proxy = {
67
+ id: address,
68
+ accountType: convertAccountProxyType(account.signMode),
69
+ name: accountName,
70
+ accounts: [account],
71
+ chainTypes: [account.chainType],
72
+ parentId: account.parentAddress,
73
+ suri: account.suri,
74
+ tokenTypes: account.tokenTypes,
75
+ accountActions: [],
76
+ isExistAccount: !!accountExists,
77
+ isExistName: nameExists
78
+ };
79
+ return {
80
+ accountProxy: proxy
81
+ };
82
+ } catch (e) {
83
+ console.error(e);
84
+ throw new Error(e.message);
85
+ }
86
+ } else {
87
+ throw new Error(t('Incorrect password'));
88
+ }
89
+ }
90
+ jsonRestoreV2({
91
+ address,
92
+ file,
93
+ isAllowed,
94
+ password,
95
+ withMasterPassword
96
+ }, onDone) {
97
+ const isPasswordValidated = this.validatePassword(file, password);
98
+ const {
99
+ promise,
100
+ reject,
101
+ resolve
102
+ } = createPromiseHandler();
103
+ if (isPasswordValidated) {
104
+ try {
105
+ const _pair = keyring.createFromJson(file);
106
+ const exists = this.state.checkAddressExists([_pair.address]);
107
+ assert(!exists, t('Account already exists under the name {{name}}', {
108
+ replace: {
109
+ name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || _pair.address
110
+ }
111
+ }));
112
+ keyring.restoreAccount(file, password, withMasterPassword);
113
+ const pair = keyring.getPair(_pair.address);
114
+ const _name = pair.meta.name || '';
115
+ const nameExists = this.state.checkNameExists(_name);
116
+ if (nameExists) {
117
+ const newName = _name.concat(' - ').concat(generateRandomString());
118
+ keyring.saveAccountMeta(pair, {
119
+ ...pair.meta,
120
+ name: newName
121
+ });
122
+ }
123
+ this.state.saveCurrentAccountProxyId(address, () => {
124
+ this.state.updateMetadataForPair();
125
+ this.state._addAddressToAuthList(address, isAllowed);
126
+ resolve([address]);
127
+ onDone();
128
+ });
129
+ } catch (error) {
130
+ reject(error);
131
+ }
132
+ } else {
133
+ reject(new Error(t('Incorrect password')));
134
+ }
135
+ return promise;
136
+ }
137
+ validatedAccountsPassword(json, password) {
138
+ try {
139
+ const decoded = u8aToString(jsonDecrypt(json, password));
140
+ return JSON.parse(decoded);
141
+ } catch (e) {
142
+ return null;
143
+ }
144
+ }
145
+ parseInfoMultiJson({
146
+ json,
147
+ password
148
+ }) {
149
+ const jsons = this.validatedAccountsPassword(json, password);
150
+ if (jsons) {
151
+ try {
152
+ const {
153
+ accountProxies,
154
+ modifyPairs
155
+ } = json;
156
+ const pairs = jsons.map(pair => keyring.createFromJson(pair));
157
+ const accountProxyMap = combineAccountsWithKeyPair(pairs, modifyPairs, accountProxies);
158
+ const result = Object.values(accountProxyMap).map(proxy => {
159
+ const rs = {
160
+ ...proxy,
161
+ isExistAccount: false,
162
+ isExistName: false
163
+ };
164
+ const accountExists = this.state.checkAddressExists(proxy.accounts.map(account => account.address));
165
+ const nameExists = this.state.checkNameExists(proxy.name);
166
+ rs.isExistAccount = !!accountExists;
167
+ rs.isExistName = nameExists;
168
+ rs.name = accountExists ? accountExists.name : proxy.name;
169
+ return rs;
170
+ });
171
+ return {
172
+ accountProxies: result
173
+ };
174
+ } catch (e) {
175
+ console.error(e);
176
+ throw new Error(e.message);
177
+ }
178
+ } else {
179
+ throw new Error(t('Incorrect password'));
180
+ }
181
+ }
182
+ batchRestoreV2({
183
+ file,
184
+ isAllowed,
185
+ password,
186
+ proxyIds: _proxyIds
187
+ }) {
188
+ const jsons = this.validatedAccountsPassword(file, password);
189
+ const {
190
+ promise,
191
+ reject,
192
+ resolve
193
+ } = createPromiseHandler();
194
+ if (jsons) {
195
+ try {
196
+ const {
197
+ accountProxies,
198
+ modifyPairs
199
+ } = file;
200
+ const pairs = jsons.map(pair => keyring.createFromJson(pair));
201
+ const accountProxyMap = combineAccountsWithKeyPair(pairs, modifyPairs, accountProxies);
202
+ const rawProxyIds = _proxyIds && _proxyIds.length ? _proxyIds : Object.keys(accountProxyMap);
203
+ let _exists;
204
+ const proxiesChangeName = {};
205
+ const accountNameDuplicates = this.state.getDuplicateAccountNames(Object.values(accountProxyMap).filter(({
206
+ id
207
+ }) => rawProxyIds.includes(id)));
208
+ const filteredAccountProxies = Object.fromEntries(Object.entries(accountProxyMap).filter(([proxyId, accountProxy]) => {
209
+ if (!rawProxyIds.includes(proxyId)) {
210
+ return false;
211
+ }
212
+ const addresses = accountProxy.accounts.map(account => account.address);
213
+ const exists = this.state.checkAddressExists(addresses);
214
+ const name = accountProxy.name;
215
+ if (this.state.checkNameExists(name) || accountNameDuplicates.includes(name)) {
216
+ proxiesChangeName[proxyId] = name.concat(' - ').concat(generateRandomString());
217
+ }
218
+ _exists = exists;
219
+ return !exists;
220
+ }));
221
+ const addresses = Object.values(filteredAccountProxies).flatMap(proxy => proxy.accounts.map(account => account.address));
222
+ const proxyIds = Object.values(filteredAccountProxies).flatMap(proxy => proxy.id);
223
+ if (!addresses.length) {
224
+ if (_exists) {
225
+ throw new Error(t('Account already exists under the name {{name}}', {
226
+ replace: {
227
+ name: _exists.name || _exists.address || ''
228
+ }
229
+ }));
230
+ } else {
231
+ throw new Error(t('No accounts found to import'));
232
+ }
233
+ }
234
+ const _accountProxies = this.state.value.accountProxy;
235
+ const _modifyPairs = this.state.value.modifyPair;
236
+ const currentProxyId = this.state.value.currentAccount.proxyId;
237
+ const nextAccountProxyId = !proxyIds.length ? currentProxyId : proxyIds.length === 1 ? proxyIds[0] : ALL_ACCOUNT_KEY;
238
+ if (accountProxies) {
239
+ for (const proxyId of proxyIds) {
240
+ const accountProxy = accountProxies[proxyId];
241
+ if (accountProxy) {
242
+ if (proxiesChangeName[proxyId]) {
243
+ accountProxy.name = proxiesChangeName[proxyId];
244
+ }
245
+ _accountProxies[proxyId] = accountProxy;
246
+ }
247
+ }
248
+ }
249
+ if (modifyPairs) {
250
+ for (const [key, modifyPair] of Object.entries(modifyPairs)) {
251
+ if (proxyIds.includes(modifyPair.accountProxyId || '')) {
252
+ _modifyPairs[key] = modifyPair;
253
+ }
254
+ }
255
+ }
256
+ this.state.upsertAccountProxy(_accountProxies);
257
+ this.state.upsertModifyPairs(_modifyPairs);
258
+ keyring.restoreAccounts(file, password, addresses);
259
+ for (const [proxyId, accountProxy] of Object.entries(accountProxyMap)) {
260
+ const name = proxiesChangeName[proxyId];
261
+ if (name) {
262
+ for (const account of accountProxy.accounts) {
263
+ const pair = keyring.getPair(account.address);
264
+ keyring.saveAccountMeta(pair, {
265
+ ...pair.meta,
266
+ name
267
+ });
268
+ }
269
+ }
270
+ }
271
+ const successAddressList = addresses.reduce((rs, address) => {
272
+ try {
273
+ const account = keyring.getPair(address);
274
+ if (account) {
275
+ rs.push(address);
276
+ }
277
+ } catch (error) {
278
+ console.log(error);
279
+ }
280
+ return rs;
281
+ }, []);
282
+ this.state.saveCurrentAccountProxyId(nextAccountProxyId, () => {
283
+ this.state.updateMetadataForPair();
284
+ this.state._addAddressesToAuthList(addresses, isAllowed);
285
+ resolve(successAddressList);
286
+ });
287
+ } catch (error) {
288
+ throw new Error(error.message);
289
+ }
290
+ } else {
291
+ reject(new Error(t('Incorrect password')));
292
+ }
293
+ return promise;
294
+ }
295
+ async batchExportV2(request) {
296
+ const {
297
+ password,
298
+ proxyIds
299
+ } = request;
300
+ try {
301
+ if (proxyIds && !proxyIds.length) {
302
+ throw new Error(t('No accounts found to export'));
303
+ }
304
+ const _accountProxy = this.state.value.accountProxy;
305
+ const _modifyPair = this.state.value.modifyPair;
306
+ const _account = this.state.value.accounts;
307
+ const _proxyIds = proxyIds || Object.keys(_account);
308
+ const modifyPairs = Object.fromEntries(Object.entries(_modifyPair).filter(([, modifyPair]) => _proxyIds.includes(modifyPair.accountProxyId || '')));
309
+ const accountProxies = Object.fromEntries(Object.entries(_accountProxy).filter(([, proxy]) => _proxyIds.includes(proxy.id)));
310
+ const addresses = Object.values(_account).filter(account => _proxyIds.includes(account.id)).flatMap(proxy => proxy.accounts.map(account => account.address));
311
+ const rs = await keyring.backupAccounts(password, addresses);
312
+ if (Object.keys(modifyPairs).length && Object.keys(accountProxies).length) {
313
+ rs.accountProxies = accountProxies;
314
+ rs.modifyPairs = modifyPairs;
315
+ }
316
+ return {
317
+ exportedJson: rs
318
+ };
319
+ } catch (e) {
320
+ const error = e;
321
+ if (error.message === 'Invalid master password') {
322
+ throw new Error(t('Incorrect password'));
323
+ } else {
324
+ throw error;
325
+ }
326
+ }
327
+ }
328
+ }
@@ -0,0 +1,11 @@
1
+ import { RequestAccountCreateHardwareMultiple, RequestAccountCreateHardwareV2 } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { AccountBaseHandler } from './Base';
3
+ /**
4
+ * @class AccountLedgerHandler
5
+ * @extends AccountBaseHandler
6
+ * @description Handler for Ledger account actions
7
+ * */
8
+ export declare class AccountLedgerHandler extends AccountBaseHandler {
9
+ accountsCreateHardwareV2(request: RequestAccountCreateHardwareV2): Promise<boolean>;
10
+ accountsCreateHardwareMultiple({ accounts }: RequestAccountCreateHardwareMultiple): Promise<boolean>;
11
+ }
@@ -0,0 +1,158 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
5
+ import { keyring } from '@subwallet/ui-keyring';
6
+ import { t } from 'i18next';
7
+ import { assert } from '@polkadot/util';
8
+ import { AccountBaseHandler } from "./Base.js";
9
+
10
+ /**
11
+ * @class AccountLedgerHandler
12
+ * @extends AccountBaseHandler
13
+ * @description Handler for Ledger account actions
14
+ * */
15
+ export class AccountLedgerHandler extends AccountBaseHandler {
16
+ /* Ledger */
17
+
18
+ /* For custom derive path */
19
+ async accountsCreateHardwareV2(request) {
20
+ const {
21
+ accountIndex,
22
+ address,
23
+ addressOffset,
24
+ genesisHash,
25
+ hardwareType,
26
+ isAllowed,
27
+ isEthereum,
28
+ isGeneric,
29
+ name,
30
+ originGenesisHash
31
+ } = request;
32
+ const exists = this.state.checkAddressExists([address]);
33
+ assert(!exists, t('Account already exists under the name {{name}}', {
34
+ replace: {
35
+ name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || address
36
+ }
37
+ }));
38
+ const baseMeta = {
39
+ name,
40
+ hardwareType,
41
+ accountIndex,
42
+ addressOffset,
43
+ genesisHash,
44
+ originGenesisHash,
45
+ isGeneric
46
+ };
47
+ const type = isEthereum ? 'ethereum' : 'sr25519';
48
+ const pair = keyring.keyring.createFromAddress(address, {
49
+ ...baseMeta,
50
+ isExternal: true,
51
+ isHardware: true,
52
+ availableGenesisHashes: isGeneric ? undefined : [genesisHash]
53
+ }, null, type);
54
+ const _address = pair.address;
55
+ const modifiedPairs = this.state.modifyPairs;
56
+ modifiedPairs[_address] = {
57
+ migrated: true,
58
+ key: _address
59
+ };
60
+ this.state.upsertModifyPairs(modifiedPairs);
61
+ keyring.addPair(pair, false);
62
+ await new Promise(resolve => {
63
+ this.state.saveCurrentAccountProxyId(_address, () => {
64
+ this.state._addAddressToAuthList(_address, isAllowed || false);
65
+ resolve();
66
+ });
67
+ });
68
+ return true;
69
+ }
70
+
71
+ /* For multi select */
72
+ async accountsCreateHardwareMultiple({
73
+ accounts
74
+ }) {
75
+ const addresses = [];
76
+ if (!accounts.length) {
77
+ throw new Error(t('Can\'t find an account. Please try again'));
78
+ }
79
+ const exists = this.state.checkAddressExists(accounts.map(account => account.address));
80
+ assert(!exists, t('Account already exists under the name {{name}}', {
81
+ replace: {
82
+ name: (exists === null || exists === void 0 ? void 0 : exists.name) || (exists === null || exists === void 0 ? void 0 : exists.address) || ''
83
+ }
84
+ }));
85
+ const slugMap = {};
86
+ const modifyPairs = this.state.modifyPairs;
87
+ const pairs = [];
88
+ for (const account of accounts) {
89
+ const {
90
+ accountIndex,
91
+ address,
92
+ addressOffset,
93
+ genesisHash,
94
+ hardwareType,
95
+ isEthereum,
96
+ isGeneric,
97
+ name,
98
+ originGenesisHash
99
+ } = account;
100
+ const baseMeta = {
101
+ name,
102
+ hardwareType,
103
+ accountIndex,
104
+ addressOffset,
105
+ genesisHash,
106
+ originGenesisHash,
107
+ isGeneric
108
+ };
109
+ const type = isEthereum ? 'ethereum' : 'sr25519';
110
+ const pair = keyring.keyring.createFromAddress(address, {
111
+ ...baseMeta,
112
+ isExternal: true,
113
+ isHardware: true,
114
+ availableGenesisHashes: isGeneric ? undefined : [genesisHash]
115
+ }, null, type);
116
+ if (isEthereum) {
117
+ slugMap.ethereum = 'ethereum';
118
+ } else {
119
+ const slug = this.state.findNetworkKeyByGenesisHash(genesisHash);
120
+ if (slug) {
121
+ slugMap[slug] = slug;
122
+ }
123
+ }
124
+ const _address = pair.address;
125
+ modifyPairs[_address] = {
126
+ migrated: true,
127
+ key: _address
128
+ };
129
+ addresses.push(_address);
130
+ pairs.push(pair);
131
+ }
132
+
133
+ // const currentAccount = this.#koniState.keyringService.context.currentAccount;
134
+ // const allGenesisHash = currentAccount?.allGenesisHash || undefined;
135
+
136
+ this.state.upsertModifyPairs(modifyPairs);
137
+ for (const pair of pairs) {
138
+ keyring.addPair(pair, false);
139
+ }
140
+ await new Promise(resolve => {
141
+ this.state._addAddressesToAuthList(addresses, true);
142
+ resolve();
143
+ });
144
+ if (addresses.length <= 1) {
145
+ this.state.saveCurrentAccountProxyId(addresses[0]);
146
+ } else {
147
+ this.state.saveCurrentAccountProxyId(ALL_ACCOUNT_KEY);
148
+ }
149
+ if (Object.keys(slugMap).length) {
150
+ for (const chainSlug of Object.keys(slugMap)) {
151
+ this.state.enableChain(chainSlug);
152
+ }
153
+ }
154
+ return true;
155
+ }
156
+
157
+ /* Ledger */
158
+ }
@@ -0,0 +1,15 @@
1
+ import { RequestAccountCreateSuriV2, RequestExportAccountProxyMnemonic, RequestMnemonicCreateV2, RequestMnemonicValidateV2, ResponseAccountCreateSuriV2, ResponseExportAccountProxyMnemonic, ResponseMnemonicCreateV2, ResponseMnemonicValidateV2 } from '@subwallet/extension-base/types';
2
+ import { AccountBaseHandler } from './Base';
3
+ export declare const SEED_DEFAULT_LENGTH = 12;
4
+ export declare const SEED_LENGTHS: number[];
5
+ /**
6
+ * @class AccountMnemonicHandler
7
+ * @extends AccountBaseHandler
8
+ * @description Handler for account's mnemonic
9
+ * */
10
+ export declare class AccountMnemonicHandler extends AccountBaseHandler {
11
+ mnemonicCreateV2({ length, mnemonic: _seed, type }: RequestMnemonicCreateV2): Promise<ResponseMnemonicCreateV2>;
12
+ mnemonicValidateV2({ mnemonic }: RequestMnemonicValidateV2): ResponseMnemonicValidateV2;
13
+ accountsCreateSuriV2(request: RequestAccountCreateSuriV2): ResponseAccountCreateSuriV2;
14
+ exportAccountProxyMnemonic({ password, proxyId }: RequestExportAccountProxyMnemonic): ResponseExportAccountProxyMnemonic;
15
+ }