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