@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,629 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ALL_ACCOUNT_KEY, UPGRADE_DUPLICATE_ACCOUNT_NAME } from '@subwallet/extension-base/constants';
5
+ import { AccountProxyStoreSubject, CurrentAccountStoreSubject, ModifyPairStoreSubject } from '@subwallet/extension-base/services/keyring-service/context/stores';
6
+ import { SWStorage } from '@subwallet/extension-base/storage';
7
+ import { AccountRefStore } from '@subwallet/extension-base/stores';
8
+ import { AccountProxyType } from '@subwallet/extension-base/types';
9
+ import { addLazy, combineAccountsWithSubjectInfo, isAddressValidWithAuthType, isSameAddress, parseUnifiedSuriToDerivationPath } from '@subwallet/extension-base/utils';
10
+ import { generateRandomString } from '@subwallet/extension-base/utils/getId';
11
+ import { EthereumKeypairTypes } from '@subwallet/keyring/types';
12
+ import { keyring } from '@subwallet/ui-keyring';
13
+ import { BehaviorSubject, combineLatest, filter, first } from 'rxjs';
14
+ export class AccountState {
15
+ // Current account
16
+ _currentAccount = new CurrentAccountStoreSubject();
17
+
18
+ // Account proxies
19
+ _accountProxy = new AccountProxyStoreSubject();
20
+
21
+ // Modify pairs
22
+ _modifyPair = new ModifyPairStoreSubject();
23
+
24
+ // Observable of accounts, pairs and contacts
25
+ contactSubject = keyring.addresses.subject;
26
+ pairSubject = keyring.accounts.subject;
27
+ accountSubject = new BehaviorSubject({});
28
+
29
+ // Old from Polkadot-js
30
+ accountRefStore = new AccountRefStore();
31
+
32
+ // Save before account info to check if accounts changed (injected accounts)
33
+ beforeAccount = this.pairSubject.value;
34
+ constructor(koniState) {
35
+ this.koniState = koniState;
36
+ this._injected = false;
37
+ this.koniState.eventService.waitCryptoReady.then(() => {
38
+ // Load current account
39
+ this._currentAccount.init();
40
+ // Load modify pairs
41
+ this._modifyPair.init();
42
+ // Load account proxies
43
+ this._accountProxy.init();
44
+ this.subscribeAccounts().catch(console.error);
45
+ }).catch(console.error);
46
+ }
47
+ async subscribeAccounts() {
48
+ // Wait until account ready
49
+ await this.koniState.eventService.waitAccountReady;
50
+ this.beforeAccount = {
51
+ ...this.pairSubject.value
52
+ };
53
+ const pairs = this.pairSubject.asObservable();
54
+ const modifyPairs = this._modifyPair.observable;
55
+ const accountGroups = this._accountProxy.observable;
56
+ const chainInfoMap = this.koniState.chainService.subscribeChainInfoMap().asObservable();
57
+ let fireOnFirst = true;
58
+ pairs.subscribe(subjectInfo => {
59
+ // Check if accounts changed
60
+ const beforeAddresses = Object.keys(this.beforeAccount);
61
+ const afterAddresses = Object.keys(subjectInfo);
62
+ if (beforeAddresses.length > afterAddresses.length) {
63
+ const removedAddresses = beforeAddresses.filter(address => !afterAddresses.includes(address));
64
+
65
+ // Remove account
66
+ removedAddresses.forEach(address => {
67
+ this.koniState.eventService.emit('account.remove', address);
68
+ });
69
+ } else if (beforeAddresses.length < afterAddresses.length) {
70
+ const addedAddresses = afterAddresses.filter(address => !beforeAddresses.includes(address));
71
+
72
+ // Add account
73
+ addedAddresses.forEach(address => {
74
+ this.koniState.eventService.emit('account.add', address);
75
+ });
76
+ } else {
77
+ // Handle case update later
78
+ }
79
+ this.beforeAccount = {
80
+ ...subjectInfo
81
+ };
82
+ });
83
+
84
+ // This Subscribes function is used to check which accounts have duplicate names and will proceed to migrate by appending a random string.
85
+ // This function will filter values that meet the condition to ensure that the number of `accountProxy` matches the number stored in the store,
86
+ // and then emit only once.
87
+ this.accountSubject.pipe(filter(accountMap => {
88
+ const accountProxyCount = Object.values(accountMap).map(({
89
+ accounts
90
+ }) => accounts).flat().length;
91
+ if (accountProxyCount > 0) {
92
+ const addressCount = Object.keys(this.pairSubject.value).length;
93
+ return addressCount === accountProxyCount;
94
+ }
95
+ return false;
96
+ }), first()).subscribe(accountProxyMap => {
97
+ const transformedAccounts = Object.values(accountProxyMap);
98
+ const storedAccountProxyBefore = this._accountProxy.value;
99
+ const accountNameDuplicates = this.getDuplicateAccountNames(transformedAccounts);
100
+ if (accountNameDuplicates.length > 0) {
101
+ SWStorage.instance.setItem(UPGRADE_DUPLICATE_ACCOUNT_NAME, 'true').catch(console.error);
102
+ for (const accountProxy of transformedAccounts) {
103
+ if (accountNameDuplicates.includes(accountProxy.name)) {
104
+ const name = accountProxy.name.concat(' - ').concat(generateRandomString());
105
+ accountProxy.name = name;
106
+ if (!storedAccountProxyBefore[accountProxy.id]) {
107
+ const pair = keyring.getPair(accountProxy.id);
108
+ if (pair) {
109
+ keyring.saveAccountMeta(pair, {
110
+ ...pair.meta,
111
+ name
112
+ });
113
+ }
114
+ } else {
115
+ this.upsertAccountProxyByKey(accountProxy);
116
+ accountProxy.accounts.forEach(({
117
+ address
118
+ }) => {
119
+ const pair = keyring.getPair(address);
120
+ if (pair) {
121
+ keyring.saveAccountMeta(pair, {
122
+ ...pair.meta,
123
+ name
124
+ });
125
+ }
126
+ });
127
+ }
128
+ }
129
+ }
130
+ }
131
+ });
132
+ combineLatest([pairs, modifyPairs, accountGroups, chainInfoMap]).subscribe(([pairs, modifyPairs, accountGroups, chainInfoMap]) => {
133
+ addLazy('combineAccounts', () => {
134
+ const result = combineAccountsWithSubjectInfo(pairs, modifyPairs, accountGroups, chainInfoMap);
135
+ fireOnFirst = false;
136
+ this.accountSubject.next(result);
137
+ }, 300, 1800, fireOnFirst);
138
+ });
139
+ }
140
+ get injected() {
141
+ return this._injected;
142
+ }
143
+ setInjected(injected) {
144
+ this._injected = injected;
145
+ }
146
+ get pairs() {
147
+ return structuredClone(this.pairSubject.value);
148
+ }
149
+ get contacts() {
150
+ return structuredClone(this.contactSubject.value);
151
+ }
152
+ get accounts() {
153
+ return structuredClone(this.accountSubject.value);
154
+ }
155
+ get accountProxies() {
156
+ return structuredClone(this._accountProxy.value);
157
+ }
158
+ get modifyPairs() {
159
+ return structuredClone(this._modifyPair.value);
160
+ }
161
+ get value() {
162
+ const pairs = this.pairSubject;
163
+ const accounts = this.accountSubject;
164
+ const accountProxy = this._accountProxy;
165
+ const currentAccount = this._currentAccount;
166
+ const contacts = this.contactSubject;
167
+ const modifyPair = this._modifyPair;
168
+ return {
169
+ get pairs() {
170
+ return structuredClone(pairs.value);
171
+ },
172
+ get accounts() {
173
+ return structuredClone(accounts.value);
174
+ },
175
+ get accountProxy() {
176
+ return structuredClone(accountProxy.value);
177
+ },
178
+ get currentAccount() {
179
+ return structuredClone(currentAccount.value);
180
+ },
181
+ get contacts() {
182
+ return structuredClone(contacts.value);
183
+ },
184
+ get modifyPair() {
185
+ return structuredClone(modifyPair.value);
186
+ }
187
+ };
188
+ }
189
+ get observable() {
190
+ const pairs = this.pairSubject;
191
+ const accounts = this.accountSubject;
192
+ const accountProxy = this._accountProxy;
193
+ const currentAccount = this._currentAccount;
194
+ const contacts = this.contactSubject;
195
+ return {
196
+ get pairs() {
197
+ return pairs.asObservable();
198
+ },
199
+ get accounts() {
200
+ return accounts.asObservable();
201
+ },
202
+ get accountProxy() {
203
+ return accountProxy.observable;
204
+ },
205
+ get currentAccount() {
206
+ return currentAccount.observable;
207
+ },
208
+ get contacts() {
209
+ return contacts.asObservable();
210
+ }
211
+ };
212
+ }
213
+
214
+ /* Current account */
215
+
216
+ get currentAccount() {
217
+ return structuredClone(this._currentAccount.value);
218
+ }
219
+ setCurrentAccount(data, callback) {
220
+ this._currentAccount.upsertData(data);
221
+ callback && callback();
222
+ this.koniState.eventService.emit('account.updateCurrent', data);
223
+ }
224
+
225
+ /**
226
+ * Updates the current account proxy ID and emits an event to notify about the update.
227
+ * For case the proxy ID is set as `ALL_ACCOUNT_KEY`, it will be updated to the first account proxy ID if there is only one account.
228
+ *
229
+ * Note: This function should be called after account data is updated.
230
+ *
231
+ * @param _proxyId - The proxy ID to be set as the current account proxy ID.
232
+ * @param callback - Optional callback function to be executed after the current account proxy ID is updated.
233
+ * @param preventOneAccount - Optional flag to prevent setting the proxy ID if there is only one account.
234
+ */
235
+ saveCurrentAccountProxyId(_proxyId, callback, preventOneAccount) {
236
+ let result = this.currentAccount;
237
+ if (!result) {
238
+ result = {
239
+ proxyId: _proxyId
240
+ };
241
+ } else {
242
+ result.proxyId = _proxyId;
243
+ }
244
+ const {
245
+ proxyId
246
+ } = result;
247
+ if (proxyId === ALL_ACCOUNT_KEY) {
248
+ const accounts = Object.keys(this.value.accounts);
249
+ const firstAccount = accounts[0];
250
+ if (accounts.length > 1 || !firstAccount) {
251
+ // For case have more than 1 account or no account
252
+ } else {
253
+ // For case have only 1 account
254
+ if (!preventOneAccount) {
255
+ result.proxyId = accounts[0];
256
+ }
257
+ }
258
+ }
259
+ this.setCurrentAccount(result, () => {
260
+ callback && callback(result);
261
+ });
262
+ }
263
+
264
+ /* Current account */
265
+
266
+ /* Check address exists */
267
+ checkAddressExists(addresses) {
268
+ for (const address of addresses) {
269
+ try {
270
+ const pair = keyring.existsPair(address);
271
+
272
+ // ignore testing accounts
273
+ if (pair && !pair.meta.isTesting) {
274
+ const address = pair.address;
275
+ const belongsTo = this.belongUnifiedAccount(address);
276
+ if (belongsTo) {
277
+ const accountProxy = this.accountProxies[belongsTo];
278
+ return {
279
+ address,
280
+ name: accountProxy.name
281
+ };
282
+ } else {
283
+ var _pair$meta;
284
+ return {
285
+ address,
286
+ name: ((_pair$meta = pair.meta) === null || _pair$meta === void 0 ? void 0 : _pair$meta.name) || address
287
+ };
288
+ }
289
+ }
290
+ } catch (e) {}
291
+ }
292
+ return undefined;
293
+ }
294
+
295
+ /* Check address exists */
296
+ checkNameExists(name, proxyId) {
297
+ const accounts = this.accounts;
298
+ const filteredAccounts = proxyId ? Object.values(accounts).filter(account => account.id !== proxyId) : Object.values(accounts);
299
+ return filteredAccounts.some(account => account.name === name);
300
+ }
301
+
302
+ /* Get duplicate account name */
303
+ getDuplicateAccountNames = accounts => {
304
+ const duplicates = [];
305
+ const accountNameMap = accounts.reduce((map, account) => {
306
+ const counterAccountNameDuplicate = map.get(account.name) || 0;
307
+ map.set(account.name, counterAccountNameDuplicate + 1);
308
+ return map;
309
+ }, new Map());
310
+ accountNameMap.forEach((count, accountName) => {
311
+ if (count > 1) {
312
+ duplicates.push(accountName);
313
+ }
314
+ });
315
+ return duplicates;
316
+ };
317
+
318
+ /* Auth address */
319
+
320
+ _addAddressesToAuthList(addresses, isAllowed) {
321
+ this.koniState.getAuthorize(value => {
322
+ if (value && Object.keys(value).length) {
323
+ Object.keys(value).forEach(url => {
324
+ addresses.forEach(address => {
325
+ if (isAddressValidWithAuthType(address, value[url].accountAuthTypes)) {
326
+ value[url].isAllowedMap[address] = isAllowed;
327
+ }
328
+ });
329
+ });
330
+ this.koniState.setAuthorize(value);
331
+ }
332
+ });
333
+ }
334
+ changeAddressAllowedAuthList(oldAddress, newAddress) {
335
+ this.koniState.getAuthorize(value => {
336
+ if (value && Object.keys(value).length) {
337
+ const newAuthMap = Object.entries(value).reduce((acc, [url, authInfo]) => {
338
+ const isAddressExisted = Object.keys(authInfo.isAllowedMap).find(address => isSameAddress(oldAddress, address));
339
+ if (isAddressExisted) {
340
+ authInfo.isAllowedMap[newAddress] = authInfo.isAllowedMap[oldAddress];
341
+ delete authInfo.isAllowedMap[oldAddress];
342
+ }
343
+ return {
344
+ ...acc,
345
+ [url]: {
346
+ ...authInfo
347
+ }
348
+ };
349
+ }, {});
350
+ this.koniState.setAuthorize(newAuthMap);
351
+ }
352
+ });
353
+ }
354
+ _addAddressToAuthList(address, isAllowed) {
355
+ this._addAddressesToAuthList([address], isAllowed);
356
+ }
357
+
358
+ /* Auth address */
359
+
360
+ /* Account groups */
361
+
362
+ /* Upsert account group */
363
+ upsertAccountProxy(data, callback) {
364
+ this._accountProxy.upsertData(data, callback);
365
+ }
366
+ upsertAccountProxyByKey(data, callback) {
367
+ this._accountProxy.upsertByKey(data, callback);
368
+ }
369
+
370
+ /* Delete account group */
371
+ deleteAccountProxy(key, callback) {
372
+ this._accountProxy.deleteByKey(key, callback);
373
+ }
374
+
375
+ /* Is account proxy id */
376
+ isUnifiedAccount(proxyId) {
377
+ const accountProxies = this.accounts;
378
+ return Object.values(accountProxies).some(value => value.accountType === AccountProxyType.UNIFIED && value.id === proxyId);
379
+ }
380
+ belongUnifiedAccount(address) {
381
+ var _modifyPairs$address;
382
+ const modifyPairs = this.modifyPairs;
383
+ const accountProxies = this.accountProxies;
384
+ const proxyId = (_modifyPairs$address = modifyPairs[address]) === null || _modifyPairs$address === void 0 ? void 0 : _modifyPairs$address.accountProxyId;
385
+ if (proxyId) {
386
+ var _accountProxies$proxy;
387
+ return (_accountProxies$proxy = accountProxies[proxyId]) === null || _accountProxies$proxy === void 0 ? void 0 : _accountProxies$proxy.id;
388
+ } else {
389
+ return undefined;
390
+ }
391
+ }
392
+
393
+ /* Is account proxy id */
394
+ addressesByProxyId(proxyId) {
395
+ if (proxyId === ALL_ACCOUNT_KEY) {
396
+ return this.getAllAddresses();
397
+ }
398
+ const accountProxies = this.accounts;
399
+ if (accountProxies[proxyId]) {
400
+ return accountProxies[proxyId].accounts.map(account => account.address);
401
+ } else {
402
+ return [];
403
+ }
404
+ }
405
+
406
+ /* Account group */
407
+
408
+ /* Modify pairs */
409
+
410
+ /* Upsert modify pairs */
411
+ upsertModifyPairs(data) {
412
+ this._modifyPair.upsertData(data);
413
+ }
414
+
415
+ /* Modify pairs */
416
+
417
+ /* Get address for another service */
418
+
419
+ getAllAddresses() {
420
+ return keyring.getAccounts().map(account => account.address);
421
+ }
422
+ getProxyId() {
423
+ const proxyId = this.currentAccount.proxyId;
424
+ if (proxyId === '') {
425
+ return null;
426
+ }
427
+ return proxyId;
428
+ }
429
+ getDecodedAddresses(accountProxy, allowGetAllAccount = true) {
430
+ let proxyId = accountProxy;
431
+ if (!accountProxy) {
432
+ proxyId = this.getProxyId();
433
+ }
434
+ if (!proxyId) {
435
+ return [];
436
+ }
437
+ if (proxyId === ALL_ACCOUNT_KEY) {
438
+ return allowGetAllAccount ? this.getAllAddresses() : [];
439
+ }
440
+ const accountProxies = this._accountProxy.value;
441
+ const modifyPairs = this._modifyPair.value;
442
+ if (!accountProxies[proxyId]) {
443
+ return [proxyId];
444
+ } else {
445
+ return Object.keys(modifyPairs).filter(address => modifyPairs[address].accountProxyId === proxyId);
446
+ }
447
+ }
448
+
449
+ /* Get address for another service */
450
+
451
+ /**
452
+ * Account ref
453
+ * @deprecated
454
+ * */
455
+
456
+ /** @deprecated */
457
+ getAccountRefMap(callback) {
458
+ const refMap = {};
459
+ this.accountRefStore.get('refList', refList => {
460
+ if (refList) {
461
+ refList.forEach(accRef => {
462
+ accRef.forEach(acc => {
463
+ refMap[acc] = [...accRef].filter(r => !(r === acc));
464
+ });
465
+ });
466
+ }
467
+ callback(refMap);
468
+ });
469
+ }
470
+
471
+ /** @deprecated */
472
+ addAccountRef(addresses, callback) {
473
+ this.accountRefStore.get('refList', refList => {
474
+ const newList = refList ? [...refList] : [];
475
+ newList.push(addresses);
476
+ this.accountRefStore.set('refList', newList, callback);
477
+ });
478
+ }
479
+
480
+ /** @deprecated */
481
+ removeAccountRef(address, callback) {
482
+ this.accountRefStore.get('refList', refList => {
483
+ if (refList) {
484
+ refList.forEach(accRef => {
485
+ if (accRef.indexOf(address) > -1) {
486
+ accRef.splice(accRef.indexOf(address), 1);
487
+ }
488
+ if (accRef.length < 2) {
489
+ refList.splice(refList.indexOf(accRef), 1);
490
+ }
491
+ });
492
+ this.accountRefStore.set('refList', refList, () => {
493
+ callback();
494
+ });
495
+ } else {
496
+ callback();
497
+ }
498
+ });
499
+ }
500
+
501
+ /**
502
+ * Account ref
503
+ * */
504
+
505
+ /* Others */
506
+
507
+ removeNoneHardwareGenesisHash() {
508
+ const pairs = keyring.getPairs();
509
+ const needUpdatePairs = pairs.filter(({
510
+ meta: {
511
+ genesisHash,
512
+ isHardware
513
+ }
514
+ }) => !isHardware && genesisHash && genesisHash !== '');
515
+ needUpdatePairs.forEach(pair => {
516
+ keyring.saveAccountMeta(pair, {
517
+ ...pair.meta,
518
+ genesisHash: ''
519
+ });
520
+ });
521
+ }
522
+ updateMetadataForPair() {
523
+ const pairs = keyring.getPairs();
524
+ const pairMap = Object.fromEntries(pairs.map(pair => [pair.address, pair]));
525
+ const needUpdateSet = new Set();
526
+ const needUpdateGenesisHash = pairs.filter(({
527
+ meta: {
528
+ genesisHash,
529
+ isHardware
530
+ }
531
+ }) => !isHardware && genesisHash && genesisHash !== '').map(pair => pair.address);
532
+ needUpdateGenesisHash.forEach(address => {
533
+ pairMap[address].meta.genesisHash = '';
534
+ needUpdateSet.add(address);
535
+ });
536
+ const deepSearchParentId = (_parentAddress, _suri) => {
537
+ const parent = pairMap[_parentAddress];
538
+ if (parent) {
539
+ const metadata = parent.meta;
540
+ const parentAddress = metadata.parentAddress;
541
+ const parentSuri = metadata.suri;
542
+ const isExternal = metadata.isExternal;
543
+ if (parentAddress && parentSuri && !isExternal) {
544
+ const suri = [parentSuri, _suri].join('');
545
+ return deepSearchParentId(parentAddress, suri);
546
+ }
547
+ }
548
+ return [_parentAddress, _suri];
549
+ };
550
+ for (const pair of Object.values(pairMap)) {
551
+ const address = pair.address;
552
+ const metadata = pair.meta;
553
+ const parentAddress = metadata.parentAddress;
554
+ const parentSuri = metadata.suri;
555
+ if (parentAddress && parentSuri) {
556
+ const [_parentAddress, _parentSuri] = deepSearchParentId(parentAddress, parentSuri);
557
+ if (parentAddress !== _parentAddress && parentSuri !== _parentSuri) {
558
+ metadata.parentAddress = _parentAddress;
559
+ metadata.suri = _parentSuri;
560
+ needUpdateSet.add(address);
561
+ }
562
+ const hasSuri = ('suri' in metadata);
563
+ const lacksDerivationPath = !('derivationPath' in metadata);
564
+ const isEthereumType = EthereumKeypairTypes.includes(pair.type);
565
+ const isTonType = pair.type === 'ton';
566
+ const isSupportedType = isEthereumType || isTonType;
567
+ if (hasSuri && lacksDerivationPath && isSupportedType) {
568
+ metadata.derivationPath = parseUnifiedSuriToDerivationPath(metadata === null || metadata === void 0 ? void 0 : metadata.suri, pair.type);
569
+ needUpdateSet.add(address);
570
+ }
571
+ }
572
+ }
573
+ Array.from(needUpdateSet).forEach(address => {
574
+ const pair = pairMap[address];
575
+ keyring.saveAccountMeta(pair, pair.meta);
576
+ });
577
+ }
578
+ updateMetadataForProxy() {
579
+ const proxyMap = Object.fromEntries(Object.entries(this.accountProxies));
580
+ const needUpdateSet = new Set();
581
+ const deepSearchParentId = (_parentId, _suri) => {
582
+ const parent = proxyMap[_parentId];
583
+ if (parent) {
584
+ const parentId = parent.parentId;
585
+ const parentSuri = parent.suri;
586
+ if (parentId && parentSuri) {
587
+ const suri = [parentSuri, _suri].join('');
588
+ return deepSearchParentId(parentId, suri);
589
+ }
590
+ }
591
+ return [_parentId, _suri];
592
+ };
593
+ for (const proxy of Object.values(proxyMap)) {
594
+ const proxyId = proxy.id;
595
+ const parentId = proxy.parentId;
596
+ const parentSuri = proxy.suri;
597
+ if (parentId && parentSuri) {
598
+ const [_parentId, _parentSuri] = deepSearchParentId(parentId, parentSuri);
599
+ if (parentId !== _parentId && parentSuri !== _parentSuri) {
600
+ proxy.parentId = _parentId;
601
+ proxy.suri = _parentSuri;
602
+ needUpdateSet.add(proxyId);
603
+ }
604
+ }
605
+ }
606
+ Array.from(needUpdateSet).forEach(address => {
607
+ const proxyData = proxyMap[address];
608
+ this.upsertAccountProxyByKey(proxyData);
609
+ });
610
+ }
611
+ findNetworkKeyByGenesisHash(genesisHash) {
612
+ const [slug] = this.koniState.findNetworkKeyByGenesisHash(genesisHash);
613
+ return slug;
614
+ }
615
+ enableChain(slug) {
616
+ this.koniState.enableChain(slug, true).catch(console.error);
617
+ }
618
+
619
+ /* Others */
620
+
621
+ /* Reset wallet */
622
+ resetWallet() {
623
+ this.upsertModifyPairs({});
624
+ this._accountProxy.clear();
625
+ this.saveCurrentAccountProxyId(ALL_ACCOUNT_KEY);
626
+ }
627
+
628
+ /* Reset wallet */
629
+ }
@@ -0,0 +1,13 @@
1
+ import { AccountProxyStore } from '@subwallet/extension-base/stores';
2
+ import { AccountProxyData, AccountProxyStoreData } from '@subwallet/extension-base/types';
3
+ import { BehaviorSubject } from 'rxjs';
4
+ import { StoreSubject } from './Base';
5
+ export declare class AccountProxyStoreSubject extends StoreSubject<AccountProxyStoreData> {
6
+ store: AccountProxyStore;
7
+ subject: BehaviorSubject<AccountProxyStoreData>;
8
+ key: string;
9
+ defaultValue: {};
10
+ upsertByKey(data: AccountProxyData, callback?: () => void): void;
11
+ deleteByKey(key: string, callback?: () => void): void;
12
+ clear(): void;
13
+ }
@@ -0,0 +1,25 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AccountProxyStore } from '@subwallet/extension-base/stores';
5
+ import { BehaviorSubject } from 'rxjs';
6
+ import { StoreSubject } from "./Base.js";
7
+ export class AccountProxyStoreSubject extends StoreSubject {
8
+ store = new AccountProxyStore();
9
+ subject = new BehaviorSubject({});
10
+ key = 'AccountProxies';
11
+ defaultValue = {};
12
+ upsertByKey(data, callback) {
13
+ const proxyData = this.value;
14
+ proxyData[data.id] = data;
15
+ this.upsertData(proxyData, callback);
16
+ }
17
+ deleteByKey(key, callback) {
18
+ const proxyData = this.value;
19
+ delete proxyData[key];
20
+ this.upsertData(proxyData, callback);
21
+ }
22
+ clear() {
23
+ this.upsertData({});
24
+ }
25
+ }
@@ -0,0 +1,22 @@
1
+ import SubscribableStore from '@subwallet/extension-base/stores/SubscribableStore';
2
+ import { BehaviorSubject, Observable, Subscription } from 'rxjs';
3
+ export interface IStoreSubject<T> {
4
+ subscribe(callback: (data: T) => void): Subscription;
5
+ init(): void;
6
+ get value(): T;
7
+ get observable(): Observable<T>;
8
+ get countObservers(): number;
9
+ }
10
+ export declare abstract class StoreSubject<T> implements IStoreSubject<T> {
11
+ abstract store: SubscribableStore<T>;
12
+ abstract subject: BehaviorSubject<T>;
13
+ abstract key: string;
14
+ abstract defaultValue: T;
15
+ transformInitData(data: T): T;
16
+ init(): void;
17
+ get value(): T;
18
+ get observable(): Observable<T>;
19
+ get countObservers(): number;
20
+ upsertData(data: T, callback?: (data: T) => void): void;
21
+ subscribe(callback: (data: T) => void): Subscription;
22
+ }