@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,566 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.transformAddresses = exports.transformAddress = exports.transformAccounts = exports.transformAccount = exports.singleAddressToAccount = exports.pairToAccount = exports.getAccountTransactionActions = exports.getAccountTokenTypes = exports.getAccountSignMode = exports.getAccountChainType = exports.getAccountActions = exports.createAccountProxyId = exports.convertAccountProxyType = exports.combineAllAccountProxy = exports.combineAccountsWithSubjectInfo = exports.combineAccountsWithKeyPair = exports._combineAccounts = void 0;
|
|
7
|
+
var _types = require("@subwallet/chain-list/types");
|
|
8
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
9
|
+
var _constants = require("@subwallet/extension-base/constants");
|
|
10
|
+
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
11
|
+
var _types2 = require("@subwallet/extension-base/types");
|
|
12
|
+
var _keyring = require("@subwallet/keyring");
|
|
13
|
+
var _types3 = require("@subwallet/keyring/types");
|
|
14
|
+
var _utils2 = require("@subwallet/keyring/utils");
|
|
15
|
+
var _util = require("@polkadot/util");
|
|
16
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
17
|
+
var _derive = require("./derive");
|
|
18
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
|
|
21
|
+
const createAccountProxyId = (_suri, derivationPath) => {
|
|
22
|
+
let data = _suri;
|
|
23
|
+
if ((0, _utilCrypto.mnemonicValidate)(_suri)) {
|
|
24
|
+
const entropy = (0, _utilCrypto.mnemonicToEntropy)(_suri);
|
|
25
|
+
data = (0, _util.u8aToHex)(entropy);
|
|
26
|
+
if (derivationPath) {
|
|
27
|
+
data = (0, _utilCrypto.blake2AsHex)(data, 256);
|
|
28
|
+
}
|
|
29
|
+
} else if ((0, _utils2.tonMnemonicValidate)(_suri)) {
|
|
30
|
+
const entropy = (0, _keyring.tonMnemonicToEntropy)(_suri);
|
|
31
|
+
data = (0, _util.u8aToHex)(entropy);
|
|
32
|
+
if (derivationPath) {
|
|
33
|
+
data = (0, _utilCrypto.blake2AsHex)(data, 256);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (derivationPath) {
|
|
37
|
+
data = (0, _util.hexStripPrefix)(data).concat(derivationPath);
|
|
38
|
+
}
|
|
39
|
+
return (0, _utilCrypto.blake2AsHex)(data, 256);
|
|
40
|
+
};
|
|
41
|
+
exports.createAccountProxyId = createAccountProxyId;
|
|
42
|
+
const getAccountChainType = type => {
|
|
43
|
+
return type ? _types3.EthereumKeypairTypes.includes(type) ? _types2.AccountChainType.ETHEREUM : _types3.TonKeypairTypes.includes(type) ? _types2.AccountChainType.TON : _types3.BitcoinKeypairTypes.includes(type) ? _types2.AccountChainType.BITCOIN : _types2.AccountChainType.SUBSTRATE : _types2.AccountChainType.SUBSTRATE;
|
|
44
|
+
};
|
|
45
|
+
exports.getAccountChainType = getAccountChainType;
|
|
46
|
+
const getAccountSignMode = (address, _meta) => {
|
|
47
|
+
const meta = _meta;
|
|
48
|
+
if (!address || !meta) {
|
|
49
|
+
return _types2.AccountSignMode.UNKNOWN;
|
|
50
|
+
} else {
|
|
51
|
+
if (address === _constants.ALL_ACCOUNT_KEY) {
|
|
52
|
+
return _types2.AccountSignMode.ALL_ACCOUNT;
|
|
53
|
+
} else {
|
|
54
|
+
if (meta.isInjected) {
|
|
55
|
+
return _types2.AccountSignMode.INJECTED;
|
|
56
|
+
}
|
|
57
|
+
if (meta.isExternal) {
|
|
58
|
+
if (meta.isHardware) {
|
|
59
|
+
if (meta.isGeneric) {
|
|
60
|
+
return _types2.AccountSignMode.GENERIC_LEDGER;
|
|
61
|
+
} else {
|
|
62
|
+
return _types2.AccountSignMode.LEGACY_LEDGER;
|
|
63
|
+
}
|
|
64
|
+
} else if (meta.isReadOnly) {
|
|
65
|
+
return _types2.AccountSignMode.READ_ONLY;
|
|
66
|
+
} else {
|
|
67
|
+
return _types2.AccountSignMode.QR;
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
return _types2.AccountSignMode.PASSWORD;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.getAccountSignMode = getAccountSignMode;
|
|
76
|
+
const getAccountActions = (signMode, networkType, type, _meta, parentAccount) => {
|
|
77
|
+
const result = [];
|
|
78
|
+
const meta = _meta;
|
|
79
|
+
|
|
80
|
+
// JSON
|
|
81
|
+
if (signMode === _types2.AccountSignMode.PASSWORD) {
|
|
82
|
+
result.push(_types2.AccountActions.EXPORT_JSON);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Mnemonic
|
|
86
|
+
if (meta && meta.isMasterAccount) {
|
|
87
|
+
result.push(_types2.AccountActions.EXPORT_MNEMONIC);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Private key
|
|
91
|
+
if (signMode === _types2.AccountSignMode.PASSWORD) {
|
|
92
|
+
if (networkType === _types2.AccountChainType.ETHEREUM || networkType === _types2.AccountChainType.TON) {
|
|
93
|
+
result.push(_types2.AccountActions.EXPORT_PRIVATE_KEY);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// QR
|
|
98
|
+
if (signMode === _types2.AccountSignMode.PASSWORD) {
|
|
99
|
+
if (networkType === _types2.AccountChainType.ETHEREUM || networkType === _types2.AccountChainType.SUBSTRATE) {
|
|
100
|
+
result.push(_types2.AccountActions.EXPORT_QR);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Derive
|
|
105
|
+
if (signMode === _types2.AccountSignMode.PASSWORD) {
|
|
106
|
+
const deriveInfo = (0, _derive.getSoloDerivationInfo)(type, meta);
|
|
107
|
+
if (networkType === _types2.AccountChainType.SUBSTRATE) {
|
|
108
|
+
if (deriveInfo.depth === 0) {
|
|
109
|
+
result.push(_types2.AccountActions.DERIVE);
|
|
110
|
+
} else if (deriveInfo.depth === 1) {
|
|
111
|
+
if (parentAccount && parentAccount.accountActions.includes(_types2.AccountActions.DERIVE)) {
|
|
112
|
+
result.push(_types2.AccountActions.DERIVE);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else if (type !== 'ton-native') {
|
|
116
|
+
if (deriveInfo.depth === 0) {
|
|
117
|
+
if (meta && meta.isMasterAccount) {
|
|
118
|
+
result.push(_types2.AccountActions.DERIVE);
|
|
119
|
+
}
|
|
120
|
+
} else if (deriveInfo.depth === 1) {
|
|
121
|
+
if (parentAccount && parentAccount.accountActions.includes(_types2.AccountActions.DERIVE)) {
|
|
122
|
+
result.push(_types2.AccountActions.DERIVE);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Ton change wallet contract version
|
|
129
|
+
if (networkType === _types2.AccountChainType.TON && signMode !== _types2.AccountSignMode.READ_ONLY) {
|
|
130
|
+
result.push(_types2.AccountActions.TON_CHANGE_WALLET_CONTRACT_VERSION);
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
};
|
|
134
|
+
exports.getAccountActions = getAccountActions;
|
|
135
|
+
const BASE_TRANSFER_ACTIONS = [_KoniTypes.ExtrinsicType.TRANSFER_BALANCE, _KoniTypes.ExtrinsicType.TRANSFER_TOKEN];
|
|
136
|
+
const NATIVE_STAKE_ACTIONS = [_KoniTypes.ExtrinsicType.STAKING_BOND, _KoniTypes.ExtrinsicType.STAKING_UNBOND, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW,
|
|
137
|
+
// ExtrinsicType.STAKING_COMPOUNDING,
|
|
138
|
+
// ExtrinsicType.STAKING_CANCEL_COMPOUNDING,
|
|
139
|
+
_KoniTypes.ExtrinsicType.STAKING_CANCEL_UNSTAKE];
|
|
140
|
+
const POOL_STAKE_ACTIONS = [_KoniTypes.ExtrinsicType.STAKING_JOIN_POOL, _KoniTypes.ExtrinsicType.STAKING_LEAVE_POOL, _KoniTypes.ExtrinsicType.STAKING_POOL_WITHDRAW, _KoniTypes.ExtrinsicType.STAKING_CLAIM_REWARD, _KoniTypes.ExtrinsicType.JOIN_YIELD_POOL];
|
|
141
|
+
const EARN_VDOT_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_VDOT, _KoniTypes.ExtrinsicType.REDEEM_VDOT, _KoniTypes.ExtrinsicType.UNSTAKE_VDOT];
|
|
142
|
+
const EARN_LDOT_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_LDOT, _KoniTypes.ExtrinsicType.REDEEM_LDOT, _KoniTypes.ExtrinsicType.UNSTAKE_LDOT];
|
|
143
|
+
const EARN_SDOT_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_SDOT, _KoniTypes.ExtrinsicType.REDEEM_SDOT, _KoniTypes.ExtrinsicType.UNSTAKE_SDOT];
|
|
144
|
+
const EARN_QDOT_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_QDOT, _KoniTypes.ExtrinsicType.REDEEM_QDOT, _KoniTypes.ExtrinsicType.UNSTAKE_QDOT];
|
|
145
|
+
const EARN_STDOT_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_STDOT, _KoniTypes.ExtrinsicType.REDEEM_STDOT, _KoniTypes.ExtrinsicType.UNSTAKE_STDOT];
|
|
146
|
+
const EARN_VMANTA_ACTIONS = [_KoniTypes.ExtrinsicType.MINT_VMANTA, _KoniTypes.ExtrinsicType.REDEEM_VMANTA, _KoniTypes.ExtrinsicType.UNSTAKE_VMANTA];
|
|
147
|
+
const EVM_ACTIONS = [_KoniTypes.ExtrinsicType.TOKEN_SPENDING_APPROVAL, _KoniTypes.ExtrinsicType.EVM_EXECUTE];
|
|
148
|
+
const OTHER_ACTIONS = [_KoniTypes.ExtrinsicType.TRANSFER_XCM, _KoniTypes.ExtrinsicType.SEND_NFT, _KoniTypes.ExtrinsicType.SWAP, _KoniTypes.ExtrinsicType.CROWDLOAN];
|
|
149
|
+
const getAccountTransactionActions = (signMode, networkType, type, _meta, _specialNetwork) => {
|
|
150
|
+
if ([_types2.AccountSignMode.PASSWORD, _types2.AccountSignMode.INJECTED].includes(signMode)) {
|
|
151
|
+
switch (networkType) {
|
|
152
|
+
case _types2.AccountChainType.SUBSTRATE:
|
|
153
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...OTHER_ACTIONS];
|
|
154
|
+
case _types2.AccountChainType.ETHEREUM:
|
|
155
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...EVM_ACTIONS];
|
|
156
|
+
case _types2.AccountChainType.TON:
|
|
157
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
158
|
+
}
|
|
159
|
+
} else if (signMode === _types2.AccountSignMode.QR) {
|
|
160
|
+
switch (networkType) {
|
|
161
|
+
case _types2.AccountChainType.SUBSTRATE:
|
|
162
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...OTHER_ACTIONS];
|
|
163
|
+
case _types2.AccountChainType.ETHEREUM:
|
|
164
|
+
return [...(_constants.isProductionMode ? [] : [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...EVM_ACTIONS])];
|
|
165
|
+
case _types2.AccountChainType.TON:
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
} else if (signMode === _types2.AccountSignMode.GENERIC_LEDGER) {
|
|
169
|
+
switch (networkType) {
|
|
170
|
+
case _types2.AccountChainType.SUBSTRATE:
|
|
171
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_VMANTA_ACTIONS,
|
|
172
|
+
// ...EARN_LDOT_ACTIONS,
|
|
173
|
+
// ...EARN_SDOT_ACTIONS,
|
|
174
|
+
// ...EARN_QDOT_ACTIONS,
|
|
175
|
+
...OTHER_ACTIONS];
|
|
176
|
+
case _types2.AccountChainType.ETHEREUM:
|
|
177
|
+
return [...BASE_TRANSFER_ACTIONS, ...EARN_STDOT_ACTIONS, ...EVM_ACTIONS, _KoniTypes.ExtrinsicType.STAKING_WITHDRAW,
|
|
178
|
+
// For liquid staking
|
|
179
|
+
_KoniTypes.ExtrinsicType.SEND_NFT, _KoniTypes.ExtrinsicType.SWAP];
|
|
180
|
+
case _types2.AccountChainType.TON:
|
|
181
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
182
|
+
}
|
|
183
|
+
} else if (signMode === _types2.AccountSignMode.LEGACY_LEDGER) {
|
|
184
|
+
// Only for Substrate
|
|
185
|
+
const result = [];
|
|
186
|
+
const specialNetwork = _specialNetwork || '';
|
|
187
|
+
result.push(...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, _KoniTypes.ExtrinsicType.SWAP, _KoniTypes.ExtrinsicType.CROWDLOAN);
|
|
188
|
+
|
|
189
|
+
// NFT
|
|
190
|
+
if (!['astar', 'avail_mainnet'].includes(specialNetwork)) {
|
|
191
|
+
result.push(_KoniTypes.ExtrinsicType.SEND_NFT);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Earning
|
|
195
|
+
if (specialNetwork === 'bifrost') {
|
|
196
|
+
result.push(...EARN_VDOT_ACTIONS, ...EARN_VMANTA_ACTIONS);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// if (specialNetwork === 'acala') {
|
|
200
|
+
// result.push(...EARN_LDOT_ACTIONS);
|
|
201
|
+
// }
|
|
202
|
+
|
|
203
|
+
// if (specialNetwork === 'parallel') {
|
|
204
|
+
// result.push(...EARN_SDOT_ACTIONS);
|
|
205
|
+
// }
|
|
206
|
+
|
|
207
|
+
// if (specialNetwork === 'interlay') {
|
|
208
|
+
// result.push(...EARN_QDOT_ACTIONS);
|
|
209
|
+
// }
|
|
210
|
+
|
|
211
|
+
// Transfer XCM
|
|
212
|
+
if (['polkadot', 'kusama', 'statemint', 'statemine'].includes(specialNetwork)) {
|
|
213
|
+
result.push(_KoniTypes.ExtrinsicType.TRANSFER_XCM);
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
return [];
|
|
218
|
+
};
|
|
219
|
+
exports.getAccountTransactionActions = getAccountTransactionActions;
|
|
220
|
+
const getAccountTokenTypes = type => {
|
|
221
|
+
switch (type) {
|
|
222
|
+
case 'ethereum':
|
|
223
|
+
return [_types._AssetType.NATIVE, _types._AssetType.LOCAL, _types._AssetType.ERC20, _types._AssetType.ERC721];
|
|
224
|
+
case 'sr25519':
|
|
225
|
+
case 'ed25519':
|
|
226
|
+
case 'ecdsa':
|
|
227
|
+
return [_types._AssetType.NATIVE, _types._AssetType.LOCAL, _types._AssetType.PSP22, _types._AssetType.PSP34, _types._AssetType.GRC20, _types._AssetType.ERC721, _types._AssetType.VFT];
|
|
228
|
+
case 'ton':
|
|
229
|
+
case 'ton-native':
|
|
230
|
+
return [_types._AssetType.NATIVE, _types._AssetType.TEP74];
|
|
231
|
+
case 'bitcoin-44':
|
|
232
|
+
case 'bittest-44':
|
|
233
|
+
case 'bitcoin-84':
|
|
234
|
+
case 'bittest-84':
|
|
235
|
+
return [_types._AssetType.NATIVE];
|
|
236
|
+
case 'bitcoin-86':
|
|
237
|
+
case 'bittest-86':
|
|
238
|
+
return [_types._AssetType.NATIVE, _types._AssetType.RUNE, _types._AssetType.BRC20];
|
|
239
|
+
default:
|
|
240
|
+
return [];
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Transforms account data into an `AccountJson` object.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} address - The address of the account.
|
|
248
|
+
* @param {KeypairType} [_type] - The type of the keypair (optional).
|
|
249
|
+
* @param {KeyringPair$Meta} [meta] - Metadata associated with the keyring pair (optional).
|
|
250
|
+
* @param {Record<string, _ChainInfo>} [chainInfoMap] - A map of chain information (optional).
|
|
251
|
+
* If chain information is provided, add full data to account.
|
|
252
|
+
* @returns {AccountJson} The transformed account data.
|
|
253
|
+
*
|
|
254
|
+
* This function performs the following steps:
|
|
255
|
+
* 1. Determines the sign mode of the account based on the address and metadata.
|
|
256
|
+
* 2. Determines the network type of the account based on the keypair type.
|
|
257
|
+
* 3. If chain information is provided, add full data (accountActions, transactionActions) to account.
|
|
258
|
+
* 4. Returns an `AccountJson` object containing the transformed account data.
|
|
259
|
+
*/
|
|
260
|
+
exports.getAccountTokenTypes = getAccountTokenTypes;
|
|
261
|
+
const transformAccount = (address, _type, meta, chainInfoMap, parentAccount) => {
|
|
262
|
+
const signMode = getAccountSignMode(address, meta);
|
|
263
|
+
const type = _type || (0, _keyring.getKeypairTypeByAddress)(address);
|
|
264
|
+
const chainType = getAccountChainType(type);
|
|
265
|
+
let specialChain;
|
|
266
|
+
if (!chainInfoMap) {
|
|
267
|
+
return {
|
|
268
|
+
address,
|
|
269
|
+
...meta,
|
|
270
|
+
type,
|
|
271
|
+
accountActions: [],
|
|
272
|
+
transactionActions: [],
|
|
273
|
+
tokenTypes: [],
|
|
274
|
+
signMode,
|
|
275
|
+
chainType
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const genesisHash = meta === null || meta === void 0 ? void 0 : meta.genesisHash;
|
|
279
|
+
if (chainInfoMap && signMode === _types2.AccountSignMode.LEGACY_LEDGER && genesisHash) {
|
|
280
|
+
const chainInfo = Object.values(chainInfoMap).find(info => (0, _utils._getSubstrateGenesisHash)(info) === genesisHash);
|
|
281
|
+
if (chainInfo) {
|
|
282
|
+
specialChain = chainInfo.slug;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const accountActions = getAccountActions(signMode, chainType, type, meta, parentAccount);
|
|
286
|
+
const transactionActions = getAccountTransactionActions(signMode, chainType, type, meta, specialChain);
|
|
287
|
+
const tokenTypes = getAccountTokenTypes(type);
|
|
288
|
+
|
|
289
|
+
/* Account actions */
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
address,
|
|
293
|
+
...meta,
|
|
294
|
+
type,
|
|
295
|
+
accountActions,
|
|
296
|
+
transactionActions,
|
|
297
|
+
signMode,
|
|
298
|
+
chainType,
|
|
299
|
+
specialChain,
|
|
300
|
+
tokenTypes
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
exports.transformAccount = transformAccount;
|
|
304
|
+
const singleAddressToAccount = (_ref, chainInfoMap, parentAccount) => {
|
|
305
|
+
let {
|
|
306
|
+
json: {
|
|
307
|
+
address,
|
|
308
|
+
meta
|
|
309
|
+
},
|
|
310
|
+
type
|
|
311
|
+
} = _ref;
|
|
312
|
+
return transformAccount(address, type, meta, chainInfoMap, parentAccount);
|
|
313
|
+
};
|
|
314
|
+
exports.singleAddressToAccount = singleAddressToAccount;
|
|
315
|
+
const pairToAccount = (_ref2, chainInfoMap, parentAccount) => {
|
|
316
|
+
let {
|
|
317
|
+
address,
|
|
318
|
+
meta,
|
|
319
|
+
type
|
|
320
|
+
} = _ref2;
|
|
321
|
+
return transformAccount(address, type, meta, chainInfoMap, parentAccount);
|
|
322
|
+
};
|
|
323
|
+
exports.pairToAccount = pairToAccount;
|
|
324
|
+
const transformAccounts = accounts => Object.values(accounts).map(data => singleAddressToAccount(data));
|
|
325
|
+
exports.transformAccounts = transformAccounts;
|
|
326
|
+
const transformAddress = (address, meta) => {
|
|
327
|
+
const type = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
328
|
+
const chainType = getAccountChainType(type);
|
|
329
|
+
return {
|
|
330
|
+
address,
|
|
331
|
+
...meta,
|
|
332
|
+
chainType
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
exports.transformAddress = transformAddress;
|
|
336
|
+
const transformAddresses = addresses => Object.values(addresses).map(_ref3 => {
|
|
337
|
+
let {
|
|
338
|
+
json: {
|
|
339
|
+
address,
|
|
340
|
+
meta
|
|
341
|
+
}
|
|
342
|
+
} = _ref3;
|
|
343
|
+
return transformAddress(address, meta);
|
|
344
|
+
});
|
|
345
|
+
exports.transformAddresses = transformAddresses;
|
|
346
|
+
const convertAccountProxyType = accountSignMode => {
|
|
347
|
+
switch (accountSignMode) {
|
|
348
|
+
case _types2.AccountSignMode.GENERIC_LEDGER:
|
|
349
|
+
case _types2.AccountSignMode.LEGACY_LEDGER:
|
|
350
|
+
return _types2.AccountProxyType.LEDGER;
|
|
351
|
+
case _types2.AccountSignMode.QR:
|
|
352
|
+
return _types2.AccountProxyType.QR;
|
|
353
|
+
case _types2.AccountSignMode.READ_ONLY:
|
|
354
|
+
return _types2.AccountProxyType.READ_ONLY;
|
|
355
|
+
case _types2.AccountSignMode.INJECTED:
|
|
356
|
+
return _types2.AccountProxyType.INJECTED;
|
|
357
|
+
case _types2.AccountSignMode.PASSWORD:
|
|
358
|
+
return _types2.AccountProxyType.SOLO;
|
|
359
|
+
case _types2.AccountSignMode.ALL_ACCOUNT:
|
|
360
|
+
return _types2.AccountProxyType.ALL_ACCOUNT;
|
|
361
|
+
case _types2.AccountSignMode.UNKNOWN:
|
|
362
|
+
return _types2.AccountProxyType.UNKNOWN;
|
|
363
|
+
}
|
|
364
|
+
return _types2.AccountProxyType.UNKNOWN;
|
|
365
|
+
};
|
|
366
|
+
exports.convertAccountProxyType = convertAccountProxyType;
|
|
367
|
+
const _combineAccounts = (accounts, modifyPairs, accountProxies) => {
|
|
368
|
+
const temp = {};
|
|
369
|
+
for (const account of accounts) {
|
|
370
|
+
const address = account.address;
|
|
371
|
+
const modifyPair = modifyPairs[address];
|
|
372
|
+
if (modifyPair && modifyPair.accountProxyId) {
|
|
373
|
+
const accountGroup = accountProxies[modifyPair.accountProxyId];
|
|
374
|
+
if (accountGroup) {
|
|
375
|
+
if (!temp[accountGroup.id]) {
|
|
376
|
+
temp[accountGroup.id] = {
|
|
377
|
+
...accountGroup,
|
|
378
|
+
accounts: [],
|
|
379
|
+
chainTypes: [],
|
|
380
|
+
tokenTypes: [],
|
|
381
|
+
accountActions: []
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
account.proxyId = accountGroup.id;
|
|
385
|
+
temp[accountGroup.id].accounts.push(account);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
temp[address] = {
|
|
390
|
+
id: address,
|
|
391
|
+
name: account.name || account.address,
|
|
392
|
+
accounts: [{
|
|
393
|
+
...account,
|
|
394
|
+
proxyId: address
|
|
395
|
+
}],
|
|
396
|
+
chainTypes: [account.chainType],
|
|
397
|
+
parentId: account.parentAddress,
|
|
398
|
+
suri: account.derivationPath || account.suri,
|
|
399
|
+
tokenTypes: account.tokenTypes,
|
|
400
|
+
accountActions: []
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
const result = Object.fromEntries(Object.entries(temp).map(_ref4 => {
|
|
404
|
+
let [key, value] = _ref4;
|
|
405
|
+
let accountType = _types2.AccountProxyType.UNKNOWN;
|
|
406
|
+
let chainTypes = [];
|
|
407
|
+
let tokenTypes = [];
|
|
408
|
+
let accountActions = [];
|
|
409
|
+
let specialChain;
|
|
410
|
+
if (value.accounts.length > 1) {
|
|
411
|
+
accountType = _types2.AccountProxyType.UNIFIED;
|
|
412
|
+
chainTypes = Array.from(value.accounts.reduce((rs, account) => rs.add(account.chainType), new Set()));
|
|
413
|
+
tokenTypes = Array.from(value.accounts.reduce((rs, account) => {
|
|
414
|
+
for (const tokenType of account.tokenTypes) {
|
|
415
|
+
rs.add(tokenType);
|
|
416
|
+
}
|
|
417
|
+
return rs;
|
|
418
|
+
}, new Set()));
|
|
419
|
+
|
|
420
|
+
/* Account actions */
|
|
421
|
+
|
|
422
|
+
// Mnemonic
|
|
423
|
+
if (value.accounts.every(account => account.accountActions.includes(_types2.AccountActions.EXPORT_MNEMONIC))) {
|
|
424
|
+
accountActions.push(_types2.AccountActions.EXPORT_MNEMONIC);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// // Json
|
|
428
|
+
// if (value.accounts.every((account) => account.accountActions.includes(AccountActions.EXPORT_JSON))) {
|
|
429
|
+
// accountActions.push(AccountActions.EXPORT_JSON);
|
|
430
|
+
// }
|
|
431
|
+
|
|
432
|
+
// Derive
|
|
433
|
+
if (value.accounts.every(account => account.accountActions.includes(_types2.AccountActions.DERIVE))) {
|
|
434
|
+
accountActions.push(_types2.AccountActions.DERIVE);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Ton change wallet contract version
|
|
438
|
+
if (value.accounts.some(account => account.accountActions.includes(_types2.AccountActions.TON_CHANGE_WALLET_CONTRACT_VERSION))) {
|
|
439
|
+
accountActions.push(_types2.AccountActions.TON_CHANGE_WALLET_CONTRACT_VERSION);
|
|
440
|
+
}
|
|
441
|
+
} else if (value.accounts.length === 1) {
|
|
442
|
+
const account = value.accounts[0];
|
|
443
|
+
chainTypes = [account.chainType];
|
|
444
|
+
tokenTypes = account.tokenTypes;
|
|
445
|
+
accountType = convertAccountProxyType(account.signMode);
|
|
446
|
+
accountActions = account.accountActions;
|
|
447
|
+
if (account.chainType === _types2.AccountChainType.TON) {
|
|
448
|
+
accountActions = accountActions.filter(action => action !== _types2.AccountActions.DERIVE);
|
|
449
|
+
}
|
|
450
|
+
switch (account.signMode) {
|
|
451
|
+
case _types2.AccountSignMode.GENERIC_LEDGER:
|
|
452
|
+
case _types2.AccountSignMode.LEGACY_LEDGER:
|
|
453
|
+
specialChain = account.specialChain;
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return [key, {
|
|
458
|
+
...value,
|
|
459
|
+
accountType,
|
|
460
|
+
chainTypes,
|
|
461
|
+
specialChain,
|
|
462
|
+
tokenTypes,
|
|
463
|
+
accountActions
|
|
464
|
+
}];
|
|
465
|
+
}));
|
|
466
|
+
const deepSearchParentId = parentId => {
|
|
467
|
+
const parent = result[parentId];
|
|
468
|
+
if (parent && parent.parentId) {
|
|
469
|
+
return deepSearchParentId(parent.parentId);
|
|
470
|
+
}
|
|
471
|
+
return parentId;
|
|
472
|
+
};
|
|
473
|
+
for (const value of Object.values(result)) {
|
|
474
|
+
if (value.parentId) {
|
|
475
|
+
value.parentId = deepSearchParentId(value.parentId);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
const deepSearchChildren = id => {
|
|
479
|
+
const rs = [];
|
|
480
|
+
for (const accountProxy of Object.values(result)) {
|
|
481
|
+
if (accountProxy.parentId === id) {
|
|
482
|
+
rs.push(accountProxy.id);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
return rs;
|
|
486
|
+
};
|
|
487
|
+
for (const value of Object.values(result)) {
|
|
488
|
+
value.children = deepSearchChildren(value.id);
|
|
489
|
+
}
|
|
490
|
+
return result;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* @summary Use for `AccountContext` subscribe account
|
|
495
|
+
* */
|
|
496
|
+
exports._combineAccounts = _combineAccounts;
|
|
497
|
+
const combineAccountsWithSubjectInfo = (pairs, modifyPairs, accountProxies, chainInfoMap) => {
|
|
498
|
+
const accountMap = {};
|
|
499
|
+
const convertAccount = address => {
|
|
500
|
+
const value = pairs[address];
|
|
501
|
+
if (!value) {
|
|
502
|
+
throw new Error(`Unable to retrieve account '${address}'`);
|
|
503
|
+
}
|
|
504
|
+
const {
|
|
505
|
+
json: {
|
|
506
|
+
meta
|
|
507
|
+
}
|
|
508
|
+
} = value;
|
|
509
|
+
if (accountMap[address]) {
|
|
510
|
+
return accountMap[address];
|
|
511
|
+
}
|
|
512
|
+
const {
|
|
513
|
+
parentAddress
|
|
514
|
+
} = meta;
|
|
515
|
+
let parentAccount;
|
|
516
|
+
if (parentAddress) {
|
|
517
|
+
parentAccount = accountMap[parentAddress];
|
|
518
|
+
if (!parentAccount && pairs[parentAddress]) {
|
|
519
|
+
parentAccount = convertAccount(parentAddress);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
const rs = singleAddressToAccount(value, chainInfoMap, parentAccount);
|
|
523
|
+
accountMap[address] = rs;
|
|
524
|
+
return rs;
|
|
525
|
+
};
|
|
526
|
+
for (const address of Object.keys(pairs)) {
|
|
527
|
+
convertAccount(address);
|
|
528
|
+
}
|
|
529
|
+
return _combineAccounts(Object.values(accountMap), modifyPairs, accountProxies);
|
|
530
|
+
};
|
|
531
|
+
exports.combineAccountsWithSubjectInfo = combineAccountsWithSubjectInfo;
|
|
532
|
+
const combineAccountsWithKeyPair = (pairs, modifyPairs, accountProxies, chainInfoMap) => {
|
|
533
|
+
const accounts = Object.values(pairs).map(data => pairToAccount(data, chainInfoMap));
|
|
534
|
+
return _combineAccounts(accounts, modifyPairs || {}, accountProxies || {});
|
|
535
|
+
};
|
|
536
|
+
exports.combineAccountsWithKeyPair = combineAccountsWithKeyPair;
|
|
537
|
+
const combineAllAccountProxy = accountProxies => {
|
|
538
|
+
const chainTypes = new Set();
|
|
539
|
+
const tokenTypes = new Set();
|
|
540
|
+
const specialChain = accountProxies.length === 1 ? accountProxies[0].specialChain : undefined;
|
|
541
|
+
for (const accountProxy of accountProxies) {
|
|
542
|
+
// Have 4 network types, but at the moment, we only support 3 network types
|
|
543
|
+
if (chainTypes.size === 3) {
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
for (const chainType of accountProxy.chainTypes) {
|
|
547
|
+
chainTypes.add(chainType);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
for (const accountProxy of accountProxies) {
|
|
551
|
+
for (const tokenType of accountProxy.tokenTypes) {
|
|
552
|
+
tokenTypes.add(tokenType);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
return {
|
|
556
|
+
id: _constants.ALL_ACCOUNT_KEY,
|
|
557
|
+
name: 'All',
|
|
558
|
+
accounts: [],
|
|
559
|
+
accountActions: [],
|
|
560
|
+
accountType: _types2.AccountProxyType.ALL_ACCOUNT,
|
|
561
|
+
chainTypes: Array.from(chainTypes),
|
|
562
|
+
tokenTypes: Array.from(tokenTypes),
|
|
563
|
+
specialChain
|
|
564
|
+
};
|
|
565
|
+
};
|
|
566
|
+
exports.combineAllAccountProxy = combineAllAccountProxy;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAddressValidWithAuthType = void 0;
|
|
7
|
+
var _keyring = require("@subwallet/keyring");
|
|
8
|
+
var _types = require("@subwallet/keyring/types");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
const isAddressValidWithAuthType = (address, accountAuthTypes) => {
|
|
13
|
+
const keypairType = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
14
|
+
const validTypes = {
|
|
15
|
+
evm: _types.EthereumKeypairTypes,
|
|
16
|
+
substrate: _types.SubstrateKeypairTypes,
|
|
17
|
+
ton: _types.TonKeypairTypes
|
|
18
|
+
};
|
|
19
|
+
return !!(accountAuthTypes !== null && accountAuthTypes !== void 0 && accountAuthTypes.some(authType => {
|
|
20
|
+
var _validTypes$authType;
|
|
21
|
+
return (_validTypes$authType = validTypes[authType]) === null || _validTypes$authType === void 0 ? void 0 : _validTypes$authType.includes(keypairType);
|
|
22
|
+
}));
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// export const isAddressValidWithAuthType = (address: string, accountAuthType?: AccountAuthType): boolean => {
|
|
26
|
+
// const keypairType = getKeypairTypeByAddress(address);
|
|
27
|
+
//
|
|
28
|
+
// if (!['ethereum', 'bitcoin-84', 'bitcoin-86', 'bittest-84', 'bittest-86'].includes(keypairType)) {
|
|
29
|
+
// return false;
|
|
30
|
+
// }
|
|
31
|
+
//
|
|
32
|
+
// if (accountAuthType === 'both') {
|
|
33
|
+
// return true;
|
|
34
|
+
// }
|
|
35
|
+
//
|
|
36
|
+
// if (accountAuthType === 'evm') {
|
|
37
|
+
// return keypairType === 'ethereum';
|
|
38
|
+
// }
|
|
39
|
+
//
|
|
40
|
+
// if (accountAuthType === 'bitcoin') {
|
|
41
|
+
// return ['bitcoin-86', 'bittest-86', 'bitcoin-84', 'bittest-84'].includes(keypairType);
|
|
42
|
+
// }
|
|
43
|
+
//
|
|
44
|
+
// return false;
|
|
45
|
+
// };
|
|
46
|
+
exports.isAddressValidWithAuthType = isAddressValidWithAuthType;
|
package/cjs/utils/getId.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.generateRandomString = void 0;
|
|
6
7
|
exports.getId = getId;
|
|
8
|
+
var _utilCrypto = require("@polkadot/util-crypto");
|
|
7
9
|
var _defaults = require("../defaults");
|
|
8
10
|
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
9
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -11,4 +13,9 @@ var _defaults = require("../defaults");
|
|
|
11
13
|
let counter = 0;
|
|
12
14
|
function getId() {
|
|
13
15
|
return `${_defaults.ID_PREFIX}.${Date.now()}.${++counter}`;
|
|
14
|
-
}
|
|
16
|
+
}
|
|
17
|
+
const generateRandomString = function () {
|
|
18
|
+
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 6;
|
|
19
|
+
return Buffer.from((0, _utilCrypto.randomAsU8a)(Math.ceil(length / 2))).toString('hex').slice(0, length);
|
|
20
|
+
};
|
|
21
|
+
exports.generateRandomString = generateRandomString;
|