@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
@@ -10,6 +10,8 @@ import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
10
10
  import { _getChainNativeTokenSlug, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
11
11
  import DetectAccountBalanceStore from '@subwallet/extension-base/stores/DetectAccountBalance';
12
12
  import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwallet/extension-base/utils';
13
+ import { getKeypairTypeByAddress } from '@subwallet/keyring';
14
+ import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
13
15
  import keyring from '@subwallet/ui-keyring';
14
16
  import { t } from 'i18next';
15
17
  import { BehaviorSubject } from 'rxjs';
@@ -38,7 +40,7 @@ export class BalanceService {
38
40
  */
39
41
  constructor(state) {
40
42
  this.state = state;
41
- this.balanceMap = new BalanceMapImpl();
43
+ this.balanceMap = new BalanceMapImpl(state);
42
44
  }
43
45
 
44
46
  /** Init service */
@@ -61,7 +63,7 @@ export class BalanceService {
61
63
  /** Restore balance map */
62
64
  async loadData() {
63
65
  const backupBalanceData = await this.state.dbService.getStoredBalance();
64
- this.balanceMap.updateBalanceItems(backupBalanceData, true);
66
+ this.balanceMap.updateBalanceItems(backupBalanceData, ALL_ACCOUNT_KEY);
65
67
  }
66
68
 
67
69
  /** Start service */
@@ -127,7 +129,7 @@ export class BalanceService {
127
129
  }
128
130
  }
129
131
  events.forEach(event => {
130
- if (event.type === 'account.remove') {
132
+ if (event.type === 'account.remove' || event.type === 'accountProxy.remove') {
131
133
  removedAddresses.push(event.data[0]);
132
134
  lazyTime = 1000;
133
135
  }
@@ -187,8 +189,9 @@ export class BalanceService {
187
189
  const chainInfoMap = this.state.chainService.getChainInfoMap();
188
190
  const evmApiMap = this.state.chainService.getEvmApiMap();
189
191
  const substrateApiMap = this.state.chainService.getSubstrateApiMap();
192
+ const tonApiMap = this.state.chainService.getTonApiMap();
190
193
  let unsub = noop;
191
- unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
194
+ unsub = subscribeBalance([address], [chain], [tSlug], assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
192
195
  const rs = result[0];
193
196
  if (rs.tokenSlug === tSlug) {
194
197
  hasError = false;
@@ -281,10 +284,12 @@ export class BalanceService {
281
284
  this.balanceUpdateCache.push(balance);
282
285
  }
283
286
  addLazy('updateBalanceStore', () => {
284
- const isAllAccount = isAccountAll(this.state.keyringService.currentAccount.address);
285
- this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isAllAccount);
286
- if (isAllAccount) {
287
- this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[ALL_ACCOUNT_KEY])];
287
+ const proxyId = this.state.keyringService.context.currentAccount.proxyId;
288
+ const isUnifiedAccount = this.state.keyringService.context.isUnifiedAccount(proxyId);
289
+ const isAll = isAccountAll(proxyId);
290
+ this.balanceMap.updateBalanceItems(this.balanceUpdateCache, isUnifiedAccount || isAll ? proxyId : undefined);
291
+ if (isUnifiedAccount || isAll) {
292
+ this.balanceUpdateCache = [...this.balanceUpdateCache, ...Object.values(this.balanceMap.map[proxyId])];
288
293
  }
289
294
  this.updateBalanceStore(this.balanceUpdateCache);
290
295
  this.balanceUpdateCache = [];
@@ -312,7 +317,7 @@ export class BalanceService {
312
317
  async runSubscribeBalances() {
313
318
  await Promise.all([this.state.eventService.waitKeyringReady, this.state.eventService.waitChainReady]);
314
319
  this.runUnsubscribeBalances();
315
- const addresses = this.state.getDecodedAddresses();
320
+ const addresses = this.state.keyringService.context.getDecodedAddresses();
316
321
  if (!addresses.length) {
317
322
  return;
318
323
  }
@@ -324,13 +329,14 @@ export class BalanceService {
324
329
  const chainInfoMap = this.state.chainService.getChainInfoMap();
325
330
  const evmApiMap = this.state.chainService.getEvmApiMap();
326
331
  const substrateApiMap = this.state.chainService.getSubstrateApiMap();
332
+ const tonApiMap = this.state.chainService.getTonApiMap();
327
333
  const activeChainSlugs = Object.keys(this.state.getActiveChainInfoMap());
328
334
  const assetState = this.state.chainService.subscribeAssetSettings().value;
329
335
  const assets = Object.values(assetMap).filter(asset => {
330
336
  var _assetState$asset$slu;
331
337
  return activeChainSlugs.includes(asset.originChain) && ((_assetState$asset$slu = assetState[asset.slug]) === null || _assetState$asset$slu === void 0 ? void 0 : _assetState$asset$slu.visible);
332
338
  }).map(asset => asset.slug);
333
- const unsub = subscribeBalance(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, result => {
339
+ const unsub = subscribeBalance(addresses, activeChainSlugs, assets, assetMap, chainInfoMap, substrateApiMap, evmApiMap, tonApiMap, result => {
334
340
  !cancel && this.setBalanceItem(result);
335
341
  }, ExtrinsicType.TRANSFER_BALANCE);
336
342
  const unsub2 = this.state.subscribeMantaPayBalance();
@@ -362,10 +368,16 @@ export class BalanceService {
362
368
  this.setBalanceDetectCache(addresses);
363
369
  const assetMap = this.state.chainService.getAssetRegistry();
364
370
  const promiseList = addresses.map(address => {
365
- return this.state.subscanService.getMultiChainBalance(address).catch(e => {
366
- console.error(e);
371
+ const type = getKeypairTypeByAddress(address);
372
+ const typeValid = [...SubstrateKeypairTypes, ...EthereumKeypairTypes].includes(type);
373
+ if (typeValid) {
374
+ return this.state.subscanService.getMultiChainBalance(address).catch(e => {
375
+ console.error(e);
376
+ return null;
377
+ });
378
+ } else {
367
379
  return null;
368
- });
380
+ }
369
381
  });
370
382
  const needEnableChains = [];
371
383
  const needActiveTokens = [];
@@ -1,5 +1,5 @@
1
1
  import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
2
- import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
2
+ import { _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
3
3
  import BigN from 'bignumber.js';
4
4
  import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
5
5
  interface CreateTransferExtrinsicProps {
@@ -12,5 +12,5 @@ interface CreateTransferExtrinsicProps {
12
12
  tokenInfo: _ChainAsset;
13
13
  }
14
14
  export declare const createTransferExtrinsic: ({ from, networkKey, substrateApi, to, tokenInfo, transferAll, value }: CreateTransferExtrinsicProps) => Promise<[SubmittableExtrinsic | null, string]>;
15
- export declare const getTransferMockTxFee: (address: string, chainInfo: _ChainInfo, tokenInfo: _ChainAsset, api: _SubstrateApi | _EvmApi) => Promise<BigN>;
15
+ export declare const getTransferMockTxFee: (address: string, chainInfo: _ChainInfo, tokenInfo: _ChainAsset, api: _SubstrateApi | _EvmApi | _TonApi) => Promise<BigN>;
16
16
  export {};
@@ -5,10 +5,14 @@ import { GearApi } from '@gear-js/api';
5
5
  import { _AssetType } from '@subwallet/chain-list/types';
6
6
  import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
7
7
  import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
8
+ import { estimateTonTxFee } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
8
9
  import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
9
- import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
10
+ import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isChainTonCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
10
11
  import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
11
12
  import { getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
13
+ import { keyring } from '@subwallet/ui-keyring';
14
+ import { internal } from '@ton/core';
15
+ import { Address } from '@ton/ton';
12
16
  import BigN from 'bignumber.js';
13
17
  import { BN, u8aToHex } from '@polkadot/util';
14
18
  import { decodeAddress } from '@polkadot/util-crypto';
@@ -126,6 +130,19 @@ export const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) =
126
130
  } else {
127
131
  estimatedFee = new BigN(priority.gasPrice).multipliedBy(gasLimit);
128
132
  }
133
+ } else if (_isChainTonCompatible(chainInfo) && _isTokenTransferredByTon(tokenInfo)) {
134
+ const mockWalletContract = keyring.getPair(address).ton.currentContract;
135
+ const tonApi = api;
136
+ const maxBlance = await tonApi.getBalance(Address.parse(address));
137
+ const mockMessage = internal({
138
+ to: address,
139
+ // anyAddress
140
+ value: maxBlance,
141
+ // estimate value
142
+ bounce: false // anyMode
143
+ });
144
+
145
+ estimatedFee = new BigN((await estimateTonTxFee(tonApi, [mockMessage], mockWalletContract)).toString());
129
146
  } else {
130
147
  var _paymentInfo$partialF;
131
148
  const substrateApi = api;
@@ -0,0 +1,25 @@
1
+ import { _ChainAsset } from '@subwallet/chain-list/types';
2
+ import { _TonApi } from '@subwallet/extension-base/services/chain-service/types';
3
+ import { MessageRelaxed } from '@ton/core';
4
+ interface TonTransactionConfigProps {
5
+ tokenInfo: _ChainAsset;
6
+ from: string;
7
+ to: string;
8
+ networkKey: string;
9
+ value: string;
10
+ transferAll: boolean;
11
+ tonApi: _TonApi;
12
+ }
13
+ export interface TonTransactionConfig {
14
+ from: string;
15
+ to: string;
16
+ networkKey: string;
17
+ value: string;
18
+ messagePayload: string;
19
+ messages: MessageRelaxed[];
20
+ estimateFee: string;
21
+ seqno: number;
22
+ transferAll: boolean;
23
+ }
24
+ export declare function createTonTransaction({ from, networkKey, to, tokenInfo, tonApi, transferAll, value }: TonTransactionConfigProps): Promise<[TonTransactionConfig | null, string]>;
25
+ export {};
@@ -0,0 +1,127 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { INIT_FEE_JETTON_TRANSFER, TON_OPCODES } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts';
5
+ import { cellToBase64Str, estimateTonTxFee, getWalletQueryId, messageRelaxedToCell } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
6
+ import { _getContractAddressOfToken, _isJettonToken, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
7
+ import { keyring } from '@subwallet/ui-keyring';
8
+ import { beginCell, fromNano, internal, toNano } from '@ton/core';
9
+ import { Address, JettonMaster } from '@ton/ton';
10
+ export async function createTonTransaction({
11
+ from,
12
+ networkKey,
13
+ to,
14
+ tokenInfo,
15
+ tonApi,
16
+ transferAll,
17
+ value
18
+ }) {
19
+ if (_isNativeToken(tokenInfo)) {
20
+ return createTonNativeTransaction({
21
+ from,
22
+ to,
23
+ networkKey,
24
+ tokenInfo,
25
+ value: value || '0',
26
+ transferAll: transferAll,
27
+ tonApi
28
+ });
29
+ }
30
+ if (_isJettonToken(tokenInfo)) {
31
+ return createJettonTransaction({
32
+ from,
33
+ to,
34
+ networkKey,
35
+ tokenInfo,
36
+ value: value || '0',
37
+ transferAll: transferAll,
38
+ tonApi
39
+ });
40
+ }
41
+ return [null, value];
42
+ }
43
+ async function createTonNativeTransaction({
44
+ from,
45
+ networkKey,
46
+ to,
47
+ tonApi,
48
+ transferAll,
49
+ value
50
+ }) {
51
+ const walletContract = keyring.getPair(from).ton.currentContract;
52
+ const contract = tonApi.open(walletContract);
53
+ const seqno = await contract.getSeqno();
54
+ const messages = internal({
55
+ to: to,
56
+ value: fromNano(value),
57
+ bounce: false // todo: check and update the send bounced logic
58
+ });
59
+
60
+ const messagePayload = cellToBase64Str(messageRelaxedToCell(messages));
61
+ const estimateExternalFee = await estimateTonTxFee(tonApi, [messages], walletContract);
62
+ const transactionObject = {
63
+ from,
64
+ to,
65
+ networkKey,
66
+ value: value,
67
+ messagePayload,
68
+ messages: [messages],
69
+ estimateFee: estimateExternalFee.toString(),
70
+ seqno,
71
+ transferAll
72
+ };
73
+ return [transactionObject, transactionObject.value];
74
+ }
75
+ async function createJettonTransaction({
76
+ from,
77
+ networkKey,
78
+ to,
79
+ tokenInfo,
80
+ tonApi,
81
+ transferAll,
82
+ value
83
+ }) {
84
+ const walletContract = keyring.getPair(from).ton.currentContract;
85
+ const sendertonAddress = Address.parse(from);
86
+ const destinationAddress = Address.parse(to);
87
+ const contract = tonApi.open(walletContract);
88
+ const seqno = await contract.getSeqno();
89
+
90
+ // retrieve jetton info
91
+ const jettonContractAddress = Address.parse(_getContractAddressOfToken(tokenInfo));
92
+ const jettonMasterContract = tonApi.open(JettonMaster.create(jettonContractAddress));
93
+ const jettonWalletAddress = await jettonMasterContract.getWalletAddress(sendertonAddress);
94
+ const messageBody = beginCell().storeUint(TON_OPCODES.JETTON_TRANSFER, 32) // opcode for jetton transfer
95
+ .storeUint(getWalletQueryId(), 64) // query id
96
+ .storeCoins(BigInt(value)) // jetton bigint amount
97
+ .storeAddress(destinationAddress).storeAddress(sendertonAddress) // response destination, who get remain token
98
+ .storeBit(0) // no custom payload
99
+ .storeCoins(BigInt(1)) // forward amount - if >0, will send notification message
100
+ .storeBit(0) // no forward payload
101
+ // .storeRef(forwardPayload)
102
+ .endCell();
103
+ const messages = internal({
104
+ to: jettonWalletAddress,
105
+ // JettonWallet of sender
106
+ value: toNano(INIT_FEE_JETTON_TRANSFER),
107
+ // set this for fee, excess later
108
+ bounce: true,
109
+ // todo: check and update the send bounced logic
110
+ body: messageBody
111
+ });
112
+ const messagePayload = cellToBase64Str(messageRelaxedToCell(messages));
113
+ const estimateExternalFee = await estimateTonTxFee(tonApi, [messages], walletContract);
114
+ const estimateFee = toNano(INIT_FEE_JETTON_TRANSFER) > estimateExternalFee ? toNano(INIT_FEE_JETTON_TRANSFER) : estimateExternalFee;
115
+ const transactionObject = {
116
+ from,
117
+ to,
118
+ networkKey,
119
+ value,
120
+ messagePayload,
121
+ messages: [messages],
122
+ estimateFee: estimateFee.toString(),
123
+ seqno,
124
+ transferAll
125
+ };
126
+ return [transactionObject, transactionObject.value];
127
+ }
@@ -1,9 +1,13 @@
1
1
  // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import { AccountChainType } from '@subwallet/extension-base/types';
4
5
  import { fetchStaticData } from '@subwallet/extension-base/utils/fetchStaticData';
5
6
  import { BehaviorSubject } from 'rxjs';
6
7
  import { DEFAULT_SERVICE_INFO } from "./constants/index.js";
8
+ const convertSupportType = support => {
9
+ return support === 'ETHEREUM' ? AccountChainType.ETHEREUM : AccountChainType.SUBSTRATE;
10
+ };
7
11
  export default class BuyService {
8
12
  #state;
9
13
  buyTokensSubject = new BehaviorSubject({});
@@ -29,7 +33,7 @@ export default class BuyService {
29
33
  serviceInfo: {
30
34
  ...DEFAULT_SERVICE_INFO
31
35
  },
32
- support: datum.support,
36
+ support: convertSupportType(datum.support),
33
37
  services: [],
34
38
  slug: datum.slug,
35
39
  symbol: datum.symbol,
@@ -1,4 +1,4 @@
1
- import { BuyService, BuyTokenInfo, SupportService } from '@subwallet/extension-base/types';
1
+ import { BuyService, OnrampAccountSupportType, SupportService } from '@subwallet/extension-base/types';
2
2
  interface _BuyTokenInfo {
3
3
  serviceInfo: Record<string, BuyService & {
4
4
  isSuspended: boolean;
@@ -6,7 +6,7 @@ interface _BuyTokenInfo {
6
6
  network: string;
7
7
  slug: string;
8
8
  symbol: string;
9
- support: BuyTokenInfo['support'];
9
+ support: OnrampAccountSupportType;
10
10
  }
11
11
  interface _BuyServiceInfo {
12
12
  id: number;
@@ -275,7 +275,7 @@ export const _XCM_TYPE = {
275
275
  PR: `${_SubstrateChainType.PARACHAIN}-${_SubstrateChainType.RELAYCHAIN}` // UMP
276
276
  };
277
277
 
278
- export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS, 'vara_network'];
278
+ export const _DEFAULT_ACTIVE_CHAINS = [..._DEFAULT_CHAINS, 'vara_network', 'ton'];
279
279
  export const EVM_PASS_CONNECT_STATUS = {
280
280
  arbitrum_one: ['*'],
281
281
  okxTest: ['*'],
@@ -208,6 +208,7 @@ export class SubstrateApi {
208
208
  console.log(`Connected to ${this.chainSlug || ''} at ${this.apiUrl}`);
209
209
  if (this.isApiReadyOnce) {
210
210
  this.handleApiReady.resolve(this);
211
+ this.isApiReady = true;
211
212
  }
212
213
  }
213
214
  onDisconnect() {
@@ -0,0 +1,52 @@
1
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
2
+ import { AccountState, TxByMsgResponse } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/types';
3
+ import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
4
+ import { _ChainConnectionStatus, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
5
+ import { PromiseHandler } from '@subwallet/extension-base/utils';
6
+ import { TonWalletContract } from '@subwallet/keyring/types';
7
+ import { Cell } from '@ton/core';
8
+ import { Address, Contract, OpenedContract } from '@ton/ton';
9
+ import { BehaviorSubject } from 'rxjs';
10
+ export declare class TonApi implements _TonApi {
11
+ chainSlug: string;
12
+ private api;
13
+ apiUrl: string;
14
+ apiError?: string;
15
+ apiRetry: number;
16
+ readonly isApiConnectedSubject: BehaviorSubject<boolean>;
17
+ readonly connectionStatusSubject: BehaviorSubject<_ChainConnectionStatus>;
18
+ isApiReady: boolean;
19
+ isApiReadyOnce: boolean;
20
+ isReadyHandler: PromiseHandler<_TonApi>;
21
+ providerName: string;
22
+ constructor(chainSlug: string, apiUrl: string, { providerName }: _ApiOptions);
23
+ get isApiConnected(): boolean;
24
+ get connectionStatus(): _ChainConnectionStatus;
25
+ private updateConnectionStatus;
26
+ get isReady(): Promise<_TonApi>;
27
+ updateApiUrl(apiUrl: string): Promise<void>;
28
+ recoverConnect(): Promise<void>;
29
+ private createProvider;
30
+ private getJsonRpc;
31
+ connect(): void;
32
+ disconnect(): Promise<void>;
33
+ destroy(): Promise<void>;
34
+ onConnect(): void;
35
+ onDisconnect(): void;
36
+ getBalance(address: Address): Promise<bigint>;
37
+ open<T extends Contract>(src: T): OpenedContract<T>;
38
+ estimateExternalMessageFee(walletContract: TonWalletContract, body: Cell, isInit: boolean, ignoreSignature?: boolean): Promise<{
39
+ '@type': "query.fees";
40
+ source_fees: {
41
+ '@type': "fees";
42
+ in_fwd_fee: number;
43
+ storage_fee: number;
44
+ gas_fee: number;
45
+ fwd_fee: number;
46
+ };
47
+ }>;
48
+ sendTonTransaction(boc: string): Promise<string>;
49
+ getTxByInMsg(extMsgHash: string): Promise<TxByMsgResponse>;
50
+ getStatusByExtMsgHash(extMsgHash: string, extrinsicType?: ExtrinsicType): Promise<[boolean, string]>;
51
+ getAccountState(address: string): Promise<AccountState>;
52
+ }
@@ -0,0 +1,204 @@
1
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { TON_CENTER_API_KEY, TON_OPCODES } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/consts';
6
+ import { getJettonTxStatus, retry } from '@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils';
7
+ import { _ChainConnectionStatus } from '@subwallet/extension-base/services/chain-service/types';
8
+ import { createPromiseHandler } from '@subwallet/extension-base/utils';
9
+ import { TonClient } from '@ton/ton';
10
+ import { BehaviorSubject } from 'rxjs';
11
+ export class TonApi {
12
+ apiRetry = 0;
13
+ isApiConnectedSubject = new BehaviorSubject(false);
14
+ connectionStatusSubject = new BehaviorSubject(_ChainConnectionStatus.DISCONNECTED);
15
+ isApiReady = false;
16
+ isApiReadyOnce = false;
17
+ constructor(chainSlug, apiUrl, {
18
+ providerName
19
+ }) {
20
+ this.chainSlug = chainSlug;
21
+ this.apiUrl = apiUrl;
22
+ this.providerName = providerName || 'unknown';
23
+ this.api = this.createProvider(apiUrl);
24
+ this.isReadyHandler = createPromiseHandler();
25
+ this.connect();
26
+ }
27
+ get isApiConnected() {
28
+ return this.isApiConnectedSubject.getValue();
29
+ }
30
+ get connectionStatus() {
31
+ return this.connectionStatusSubject.getValue();
32
+ }
33
+ updateConnectionStatus(status) {
34
+ const isConnected = status === _ChainConnectionStatus.CONNECTED;
35
+ if (isConnected !== this.isApiConnectedSubject.value) {
36
+ this.isApiConnectedSubject.next(isConnected);
37
+ }
38
+ if (status !== this.connectionStatusSubject.value) {
39
+ this.connectionStatusSubject.next(status);
40
+ }
41
+ }
42
+ get isReady() {
43
+ return this.isReadyHandler.promise;
44
+ }
45
+ async updateApiUrl(apiUrl) {
46
+ if (this.apiUrl === apiUrl) {
47
+ return;
48
+ }
49
+ await this.disconnect();
50
+
51
+ // Create new provider and api
52
+ this.apiUrl = apiUrl;
53
+ this.api = new TonClient({
54
+ endpoint: this.getJsonRpc(this.apiUrl),
55
+ apiKey: TON_CENTER_API_KEY
56
+ });
57
+ }
58
+ async recoverConnect() {
59
+ await this.disconnect();
60
+ this.connect();
61
+ await this.isReadyHandler.promise;
62
+ }
63
+ createProvider(apiUrl) {
64
+ return new TonClient({
65
+ endpoint: this.getJsonRpc(apiUrl),
66
+ apiKey: TON_CENTER_API_KEY
67
+ });
68
+ }
69
+ getJsonRpc(url) {
70
+ return `${url}/jsonRPC`;
71
+ }
72
+ connect() {
73
+ this.updateConnectionStatus(_ChainConnectionStatus.CONNECTING);
74
+ // There isn't a persistent network connection underlying TonClient. Cant check connection status.
75
+ // this.isApiReadyOnce = true;
76
+ this.onConnect();
77
+ }
78
+ async disconnect() {
79
+ this.onDisconnect();
80
+ this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
81
+ return Promise.resolve();
82
+ }
83
+ destroy() {
84
+ // Todo: implement this in the future
85
+ return this.disconnect();
86
+ }
87
+ onConnect() {
88
+ if (!this.isApiConnected) {
89
+ console.log(`Connected to ${this.chainSlug} at ${this.apiUrl}`);
90
+ this.isApiReady = true;
91
+ if (this.isApiReadyOnce) {
92
+ this.isReadyHandler.resolve(this);
93
+ }
94
+ }
95
+ this.updateConnectionStatus(_ChainConnectionStatus.CONNECTED);
96
+ }
97
+ onDisconnect() {
98
+ this.updateConnectionStatus(_ChainConnectionStatus.DISCONNECTED);
99
+ if (this.isApiConnected) {
100
+ console.warn(`Disconnected from ${this.chainSlug} of ${this.apiUrl}`);
101
+ this.isApiReady = false;
102
+ this.isReadyHandler = createPromiseHandler();
103
+ }
104
+ }
105
+
106
+ // Util functions
107
+
108
+ async getBalance(address) {
109
+ return await this.api.getBalance(address);
110
+ }
111
+ open(src) {
112
+ return this.api.open(src);
113
+ }
114
+ estimateExternalMessageFee(walletContract, body, isInit, ignoreSignature = true) {
115
+ const initCode = isInit ? null : walletContract.init.code;
116
+ const initData = isInit ? null : walletContract.init.data;
117
+ return this.api.estimateExternalMessageFee(walletContract.address, {
118
+ body: body,
119
+ ignoreSignature: ignoreSignature,
120
+ initCode: initCode,
121
+ initData: initData
122
+ });
123
+ }
124
+ async sendTonTransaction(boc) {
125
+ try {
126
+ const url = `${this.apiUrl}/api/v2/sendBocReturnHash`;
127
+ const resp = await fetch(url, {
128
+ method: 'POST',
129
+ headers: {
130
+ accept: 'application/json',
131
+ 'Content-Type': 'application/json',
132
+ 'X-API-KEY': TON_CENTER_API_KEY
133
+ },
134
+ body: JSON.stringify({
135
+ boc: boc
136
+ })
137
+ });
138
+ const extMsgInfo = await resp.json();
139
+ return extMsgInfo.result.hash;
140
+ } catch (error) {
141
+ console.error('Failed to send transaction with boc', boc);
142
+ throw error;
143
+ }
144
+ }
145
+ async getTxByInMsg(extMsgHash) {
146
+ const url = `${this.apiUrl}/api/v3/transactionsByMessage?msg_hash=${encodeURIComponent(extMsgHash)}&direction=in`;
147
+ const resp = await fetch(url, {
148
+ method: 'GET',
149
+ headers: {
150
+ accept: 'application/json',
151
+ 'Content-Type': 'application/json',
152
+ 'X-API-KEY': TON_CENTER_API_KEY
153
+ }
154
+ });
155
+ return await resp.json();
156
+ }
157
+ async getStatusByExtMsgHash(extMsgHash, extrinsicType) {
158
+ return retry(async () => {
159
+ var _externalTxInfo$out_m, _externalTxInfo$out_m2;
160
+ // retry many times to get transaction status and transaction hex
161
+ const externalTxInfoRaw = await this.getTxByInMsg(extMsgHash);
162
+ const externalTxInfo = externalTxInfoRaw.transactions[0];
163
+ const isExternalTxCompute = externalTxInfo.description.compute_ph.success;
164
+ const isExternalTxAction = externalTxInfo.description.action.success;
165
+ const base64Hex = externalTxInfo.hash;
166
+ const hex = '0x'.concat(Buffer.from(base64Hex, 'base64').toString('hex'));
167
+ if (!(isExternalTxCompute && isExternalTxAction)) {
168
+ return [false, hex];
169
+ }
170
+ if (extrinsicType === ExtrinsicType.TRANSFER_BALANCE) {
171
+ return [true, hex];
172
+ }
173
+
174
+ // get out msg info from tx
175
+ const internalMsgHash = (_externalTxInfo$out_m = externalTxInfo.out_msgs[0]) === null || _externalTxInfo$out_m === void 0 ? void 0 : _externalTxInfo$out_m.hash;
176
+ const opcode = parseInt(((_externalTxInfo$out_m2 = externalTxInfo.out_msgs[0]) === null || _externalTxInfo$out_m2 === void 0 ? void 0 : _externalTxInfo$out_m2.opcode) || '0');
177
+ if (internalMsgHash) {
178
+ // notice to update opcode check when supporting more transaction type in ton blockchain
179
+ const status = opcode === TON_OPCODES.JETTON_TRANSFER ? await getJettonTxStatus(this, internalMsgHash) : false;
180
+ return [status, hex];
181
+ }
182
+ throw new Error('Transaction not found');
183
+ }, {
184
+ retries: 10,
185
+ delay: 5000
186
+ });
187
+ }
188
+ async getAccountState(address) {
189
+ const url = `${this.apiUrl}/api/v2/getAddressState?address=${address}`;
190
+ const resp = await fetch(url, {
191
+ method: 'GET',
192
+ headers: {
193
+ accept: 'application/json',
194
+ 'Content-Type': 'application/json',
195
+ 'X-API-KEY': TON_CENTER_API_KEY
196
+ }
197
+ });
198
+ const accountStateInfo = await resp.json();
199
+ if (accountStateInfo.ok) {
200
+ return accountStateInfo.result;
201
+ }
202
+ return 'unknown';
203
+ }
204
+ }
@@ -0,0 +1,17 @@
1
+ import { ChainService } from '@subwallet/extension-base/services/chain-service';
2
+ import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
3
+ import { TonApi } from '@subwallet/extension-base/services/chain-service/handler/TonApi';
4
+ import { _ApiOptions } from '@subwallet/extension-base/services/chain-service/handler/types';
5
+ export declare class TonChainHandler extends AbstractChainHandler {
6
+ private tonApiMap;
7
+ constructor(parent?: ChainService);
8
+ getTonApiMap(): Record<string, TonApi>;
9
+ getTonApiByChain(chain: string): TonApi;
10
+ getApiByChain(chain: string): TonApi;
11
+ setTonApi(chain: string, tonApi: TonApi): void;
12
+ initApi(chainSlug: string, apiUrl: string, { onUpdateStatus, providerName }?: Omit<_ApiOptions, 'metadata'>): Promise<TonApi>;
13
+ recoverApi(chain: string): Promise<void>;
14
+ destroyTonApi(chain: string): void;
15
+ sleep(): Promise<void>;
16
+ wakeUp(): Promise<void>;
17
+ }