@subwallet/extension-base 1.2.31-0 → 1.2.33-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 -15
- 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/SubstrateApi.js +1 -0
- 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 -17
- 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/SubstrateApi.js +1 -0
- 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/mkt-campaign-service/types.d.ts +4 -0
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseRequestSign, InternalRequestSign } from '
|
|
1
|
+
import { BaseRequestSign, InternalRequestSign } from '../../transaction';
|
|
2
2
|
import { BasePoolInfo, UnstakingInfo, YieldPoolInfo } from '../info';
|
|
3
3
|
/**
|
|
4
4
|
* @interface YieldLeaveParams
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { AccountProxy, AddressJson, ResponseInputAccountSubscribe } from '@subwallet/extension-base/types';
|
|
4
|
+
export declare const _analyzeAddress: (data: string, accountProxies: AccountProxy[], contacts: AddressJson[], chainInfo: _ChainInfo, substrateApi?: _SubstrateApi) => Promise<Omit<ResponseInputAccountSubscribe, 'id'>>;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
|
|
5
|
+
import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { AccountChainType, AnalyzedGroup } from '@subwallet/extension-base/types';
|
|
7
|
+
import { isAddress } from '@polkadot/util-crypto';
|
|
8
|
+
import { _reformatAddressWithChain, reformatAddress } from "./common.js";
|
|
9
|
+
// TODO: Re-confirm to compare without
|
|
10
|
+
const isStrValidWithAddress = (str, account, chainInfo) => {
|
|
11
|
+
if (account.chainType === AccountChainType.SUBSTRATE) {
|
|
12
|
+
const reformated = reformatAddress(account.address, _getChainSubstrateAddressPrefix(chainInfo));
|
|
13
|
+
if (account.address.toLowerCase() === str || reformated.toLowerCase() === str) {
|
|
14
|
+
return 'extracted';
|
|
15
|
+
} else if (account.address.toLowerCase().includes(str) || reformated.toLowerCase().includes(str)) {
|
|
16
|
+
return 'valid';
|
|
17
|
+
}
|
|
18
|
+
} else if (account.chainType === AccountChainType.TON) {
|
|
19
|
+
const isTestnet = chainInfo.isTestnet;
|
|
20
|
+
const reformated = reformatAddress(account.address, isTestnet ? 0 : 1);
|
|
21
|
+
if (account.address.toLowerCase() === str || reformated.toLowerCase() === str) {
|
|
22
|
+
return 'extracted';
|
|
23
|
+
} else if (account.address.toLowerCase().includes(str) || reformated.toLowerCase().includes(str)) {
|
|
24
|
+
return 'valid';
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
if (account.address.toLowerCase() === str) {
|
|
28
|
+
return 'extracted';
|
|
29
|
+
} else if (account.address.toLowerCase().includes(str)) {
|
|
30
|
+
return 'valid';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return 'invalid';
|
|
34
|
+
};
|
|
35
|
+
const isNameValid = (str, name) => {
|
|
36
|
+
if (name === str) {
|
|
37
|
+
return 'extracted';
|
|
38
|
+
} else if (name.includes(str)) {
|
|
39
|
+
return 'valid';
|
|
40
|
+
} else {
|
|
41
|
+
return 'invalid';
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export const _analyzeAddress = async (data, accountProxies, contacts, chainInfo, substrateApi) => {
|
|
45
|
+
if (!data) {
|
|
46
|
+
return {
|
|
47
|
+
options: []
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const chain = chainInfo.slug;
|
|
51
|
+
const _data = data.trim().toLowerCase();
|
|
52
|
+
const options = [];
|
|
53
|
+
const currentChainType = _chainInfoToChainType(chainInfo);
|
|
54
|
+
let current;
|
|
55
|
+
|
|
56
|
+
// Filter account proxies
|
|
57
|
+
for (const accountProxy of accountProxies) {
|
|
58
|
+
const _name = accountProxy.name.trim().toLowerCase();
|
|
59
|
+
const nameCondition = isNameValid(_data, _name);
|
|
60
|
+
const filterAccounts = accountProxy.accounts.filter(account => account.chainType === currentChainType);
|
|
61
|
+
for (const account of filterAccounts) {
|
|
62
|
+
const addressCondition = isStrValidWithAddress(_data, account, chainInfo);
|
|
63
|
+
const condition = nameCondition !== 'invalid' ? nameCondition : addressCondition;
|
|
64
|
+
const rs = {
|
|
65
|
+
address: account.address,
|
|
66
|
+
proxyId: accountProxy.id,
|
|
67
|
+
analyzedGroup: AnalyzedGroup.WALLET,
|
|
68
|
+
displayName: accountProxy.name,
|
|
69
|
+
formatedAddress: _reformatAddressWithChain(account.address, chainInfo)
|
|
70
|
+
};
|
|
71
|
+
if (condition !== 'invalid') {
|
|
72
|
+
if (account.specialChain) {
|
|
73
|
+
if (account.specialChain === chain) {
|
|
74
|
+
options.push(rs);
|
|
75
|
+
if (condition === 'extracted') {
|
|
76
|
+
current = rs;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
options.push(rs);
|
|
81
|
+
if (condition === 'extracted') {
|
|
82
|
+
current = rs;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const filterContacts = contacts.filter(contact => contact.chainType === currentChainType);
|
|
89
|
+
|
|
90
|
+
// Filter address book addresses
|
|
91
|
+
for (const contact of filterContacts) {
|
|
92
|
+
const name = (contact === null || contact === void 0 ? void 0 : contact.name) || '';
|
|
93
|
+
const _name = name.trim().toLowerCase();
|
|
94
|
+
const nameCondition = isNameValid(_data, _name);
|
|
95
|
+
const addressCondition = isStrValidWithAddress(_data, contact, chainInfo);
|
|
96
|
+
const condition = nameCondition !== 'invalid' ? nameCondition : addressCondition;
|
|
97
|
+
const rs = {
|
|
98
|
+
address: contact.address,
|
|
99
|
+
analyzedGroup: contact.isRecent ? AnalyzedGroup.RECENT : AnalyzedGroup.CONTACT,
|
|
100
|
+
displayName: name,
|
|
101
|
+
formatedAddress: _reformatAddressWithChain(contact.address, chainInfo)
|
|
102
|
+
};
|
|
103
|
+
if (condition !== 'invalid') {
|
|
104
|
+
if (contact.isRecent) {
|
|
105
|
+
var _contact$recentChainS;
|
|
106
|
+
if ((_contact$recentChainS = contact.recentChainSlugs) !== null && _contact$recentChainS !== void 0 && _contact$recentChainS.includes(chain)) {
|
|
107
|
+
options.push(rs);
|
|
108
|
+
if (condition === 'extracted') {
|
|
109
|
+
current = rs;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
options.push(rs);
|
|
114
|
+
if (condition === 'extracted') {
|
|
115
|
+
current = rs;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (substrateApi) {
|
|
121
|
+
await (substrateApi === null || substrateApi === void 0 ? void 0 : substrateApi.isReady);
|
|
122
|
+
const _raw = data.trim();
|
|
123
|
+
if (chain === 'aleph' || chain === 'alephTest') {
|
|
124
|
+
if (isAddress(_raw)) {
|
|
125
|
+
const domain = await resolveAzeroAddressToDomain(_raw, chain, substrateApi.api);
|
|
126
|
+
if (domain) {
|
|
127
|
+
const rs = {
|
|
128
|
+
address: _raw,
|
|
129
|
+
analyzedGroup: AnalyzedGroup.DOMAIN,
|
|
130
|
+
displayName: domain,
|
|
131
|
+
formatedAddress: _reformatAddressWithChain(_raw, chainInfo)
|
|
132
|
+
};
|
|
133
|
+
options.push(rs);
|
|
134
|
+
if (!current) {
|
|
135
|
+
current = rs;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
const address = await resolveAzeroDomainToAddress(_raw, chain, substrateApi.api);
|
|
140
|
+
if (address) {
|
|
141
|
+
const rs = {
|
|
142
|
+
address: address,
|
|
143
|
+
analyzedGroup: AnalyzedGroup.DOMAIN,
|
|
144
|
+
displayName: _raw,
|
|
145
|
+
formatedAddress: _reformatAddressWithChain(address, chainInfo)
|
|
146
|
+
};
|
|
147
|
+
options.push(rs);
|
|
148
|
+
if (!current) {
|
|
149
|
+
current = rs;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
options,
|
|
157
|
+
current
|
|
158
|
+
};
|
|
159
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { AccountChainType } from '@subwallet/extension-base/types';
|
|
3
|
+
import { KeypairType } from '@subwallet/keyring/types';
|
|
4
|
+
export declare function isAccountAll(address?: string): boolean;
|
|
5
|
+
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
|
|
6
|
+
export declare const _reformatAddressWithChain: (address: string, chainInfo: _ChainInfo) => string;
|
|
7
|
+
export declare const getAccountChainTypeForAddress: (address: string) => AccountChainType;
|
|
8
|
+
export declare function categoryAddresses(addresses: string[]): {
|
|
9
|
+
substrate: string[];
|
|
10
|
+
evm: string[];
|
|
11
|
+
ton: string[];
|
|
12
|
+
bitcoin: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare function quickFormatAddressToCompare(address?: string): string | undefined;
|
|
15
|
+
/** @deprecated */
|
|
16
|
+
export declare const modifyAccountName: (type: KeypairType, name: string, modify: boolean) => string;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
5
|
+
import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
|
+
import { AccountChainType } from '@subwallet/extension-base/types';
|
|
7
|
+
import { getAccountChainType } from '@subwallet/extension-base/utils';
|
|
8
|
+
import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isTonAddress } from '@subwallet/keyring';
|
|
9
|
+
import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
10
|
+
export function isAccountAll(address) {
|
|
11
|
+
return address === ALL_ACCOUNT_KEY;
|
|
12
|
+
}
|
|
13
|
+
export function reformatAddress(address, networkPrefix = 42, isEthereum = false) {
|
|
14
|
+
try {
|
|
15
|
+
if (!address || address === '') {
|
|
16
|
+
return '';
|
|
17
|
+
}
|
|
18
|
+
if (isEthereumAddress(address)) {
|
|
19
|
+
return address;
|
|
20
|
+
}
|
|
21
|
+
if (isAccountAll(address)) {
|
|
22
|
+
return address;
|
|
23
|
+
}
|
|
24
|
+
const publicKey = decodeAddress(address);
|
|
25
|
+
if (isEthereum) {
|
|
26
|
+
return ethereumEncode(publicKey);
|
|
27
|
+
}
|
|
28
|
+
const type = getKeypairTypeByAddress(address);
|
|
29
|
+
if (networkPrefix < 0) {
|
|
30
|
+
return address;
|
|
31
|
+
}
|
|
32
|
+
return encodeAddress(publicKey, networkPrefix, type);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.warn('Get error while reformat address', address, e);
|
|
35
|
+
return address;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export const _reformatAddressWithChain = (address, chainInfo) => {
|
|
39
|
+
const chainType = _chainInfoToChainType(chainInfo);
|
|
40
|
+
if (chainType === AccountChainType.SUBSTRATE) {
|
|
41
|
+
return reformatAddress(address, _getChainSubstrateAddressPrefix(chainInfo));
|
|
42
|
+
} else if (chainType === AccountChainType.TON) {
|
|
43
|
+
const isTestnet = chainInfo.isTestnet;
|
|
44
|
+
return reformatAddress(address, isTestnet ? 0 : 1);
|
|
45
|
+
} else {
|
|
46
|
+
return address;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const getAccountChainTypeForAddress = address => {
|
|
50
|
+
const type = getKeypairTypeByAddress(address);
|
|
51
|
+
return getAccountChainType(type);
|
|
52
|
+
};
|
|
53
|
+
export function categoryAddresses(addresses) {
|
|
54
|
+
const substrate = [];
|
|
55
|
+
const evm = [];
|
|
56
|
+
const ton = [];
|
|
57
|
+
const bitcoin = [];
|
|
58
|
+
addresses.forEach(address => {
|
|
59
|
+
if (isEthereumAddress(address)) {
|
|
60
|
+
evm.push(address);
|
|
61
|
+
} else if (isTonAddress(address)) {
|
|
62
|
+
ton.push(address);
|
|
63
|
+
} else if (isBitcoinAddress(address)) {
|
|
64
|
+
bitcoin.push(address);
|
|
65
|
+
} else {
|
|
66
|
+
substrate.push(address);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
bitcoin,
|
|
71
|
+
evm,
|
|
72
|
+
substrate,
|
|
73
|
+
ton
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export function quickFormatAddressToCompare(address) {
|
|
77
|
+
if (!isAddress(address)) {
|
|
78
|
+
return address;
|
|
79
|
+
}
|
|
80
|
+
return reformatAddress(address, 42).toLowerCase();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @deprecated */
|
|
84
|
+
export const modifyAccountName = (type, name, modify) => {
|
|
85
|
+
if (!modify) {
|
|
86
|
+
return name;
|
|
87
|
+
}
|
|
88
|
+
let network = '';
|
|
89
|
+
switch (type) {
|
|
90
|
+
case 'sr25519':
|
|
91
|
+
case 'ed25519':
|
|
92
|
+
case 'ecdsa':
|
|
93
|
+
network = 'Substrate';
|
|
94
|
+
break;
|
|
95
|
+
case 'ethereum':
|
|
96
|
+
network = 'EVM';
|
|
97
|
+
break;
|
|
98
|
+
case 'ton':
|
|
99
|
+
case 'ton-native':
|
|
100
|
+
network = 'Ton';
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return network ? [name, network].join(' - ') : name;
|
|
104
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccountDeriveData, DeriveInfo, NextDerivePair } from '@subwallet/extension-base/types';
|
|
2
|
+
import { KeypairType, KeyringPair } from '@subwallet/keyring/types';
|
|
3
|
+
export declare const parseUnifiedSuriToDerivationPath: (suri: string, type: KeypairType) => string;
|
|
4
|
+
export declare const getSoloDerivationInfo: (type: KeypairType, metadata?: AccountDeriveData) => DeriveInfo;
|
|
5
|
+
/**
|
|
6
|
+
* @func findSoloNextDerive
|
|
7
|
+
* @return {NextDerivePair}
|
|
8
|
+
* */
|
|
9
|
+
export declare const findSoloNextDerive: (parentAddress: string) => NextDerivePair;
|
|
10
|
+
export declare const derivePair: (parentPair: KeyringPair, name: string, suri: string, derivationPath?: string) => KeyringPair;
|
|
11
|
+
export declare const getSuri: (seed: string, type?: KeypairType) => string;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { getDerivePath } from '@subwallet/keyring';
|
|
5
|
+
import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
6
|
+
import { keyring } from '@subwallet/ui-keyring';
|
|
7
|
+
import { t } from 'i18next';
|
|
8
|
+
import { assert } from '@polkadot/util';
|
|
9
|
+
import { validateEvmDerivationPath, validateOtherSubstrateDerivationPath, validateSr25519DerivationPath, validateTonDerivationPath, validateUnifiedDerivationPath } from "../validate.js";
|
|
10
|
+
export const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
11
|
+
const reg = /^\/\/(\d+)(\/\/\d+)?$/;
|
|
12
|
+
if (suri.match(reg)) {
|
|
13
|
+
const [, firstIndex, secondData] = suri.match(reg);
|
|
14
|
+
const first = parseInt(firstIndex, 10);
|
|
15
|
+
if (secondData) {
|
|
16
|
+
const [, secondIndex] = secondData.match(/\/\/(\d+)/);
|
|
17
|
+
if (type === 'ethereum') {
|
|
18
|
+
return `m/44'/60'/0'/0/${first}/${secondIndex}`;
|
|
19
|
+
} else if (type === 'ton') {
|
|
20
|
+
return `m/44'/607'/${first}'/${secondIndex}'`;
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
if (type === 'ethereum') {
|
|
24
|
+
return `m/44'/60'/0'/0/${first}`;
|
|
25
|
+
} else if (type === 'ton') {
|
|
26
|
+
return `m/44'/607'/${first}'`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (SubstrateKeypairTypes.includes(type)) {
|
|
30
|
+
return suri;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return '';
|
|
34
|
+
};
|
|
35
|
+
export const getSoloDerivationInfo = (type, metadata = {}) => {
|
|
36
|
+
const {
|
|
37
|
+
derivationPath: derivePath,
|
|
38
|
+
parentAddress,
|
|
39
|
+
suri
|
|
40
|
+
} = metadata;
|
|
41
|
+
if (suri) {
|
|
42
|
+
if (derivePath) {
|
|
43
|
+
const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : () => undefined;
|
|
44
|
+
const validateTypeRs = validateTypeFunc(derivePath);
|
|
45
|
+
if (validateTypeRs) {
|
|
46
|
+
return {
|
|
47
|
+
suri: validateTypeRs.suri,
|
|
48
|
+
depth: validateTypeRs.depth,
|
|
49
|
+
derivationPath: derivePath,
|
|
50
|
+
parentAddress,
|
|
51
|
+
autoIndexes: validateTypeRs.autoIndexes
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
return {
|
|
55
|
+
depth: 1,
|
|
56
|
+
derivationPath: derivePath,
|
|
57
|
+
parentAddress,
|
|
58
|
+
suri
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
if (SubstrateKeypairTypes.includes(type)) {
|
|
63
|
+
const _type = type;
|
|
64
|
+
const validateTypeFunc = _type === 'sr25519' ? validateSr25519DerivationPath : raw => validateOtherSubstrateDerivationPath(raw, _type);
|
|
65
|
+
const validateTypeRs = validateTypeFunc(suri);
|
|
66
|
+
if (validateTypeRs) {
|
|
67
|
+
return {
|
|
68
|
+
suri: validateTypeRs.suri,
|
|
69
|
+
depth: validateTypeRs.depth,
|
|
70
|
+
parentAddress,
|
|
71
|
+
autoIndexes: validateTypeRs.autoIndexes
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const validateUnifiedRs = validateUnifiedDerivationPath(suri);
|
|
76
|
+
if (validateUnifiedRs) {
|
|
77
|
+
const {
|
|
78
|
+
autoIndexes,
|
|
79
|
+
depth
|
|
80
|
+
} = validateUnifiedRs;
|
|
81
|
+
const derivationPath = parseUnifiedSuriToDerivationPath(suri, type);
|
|
82
|
+
return {
|
|
83
|
+
suri: suri,
|
|
84
|
+
depth,
|
|
85
|
+
derivationPath: derivationPath,
|
|
86
|
+
parentAddress,
|
|
87
|
+
autoIndexes
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
return {
|
|
91
|
+
depth: 1,
|
|
92
|
+
derivationPath: derivePath,
|
|
93
|
+
parentAddress,
|
|
94
|
+
suri
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
if (derivePath) {
|
|
100
|
+
const validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : () => undefined;
|
|
101
|
+
const validateTypeRs = validateTypeFunc(derivePath);
|
|
102
|
+
if (validateTypeRs) {
|
|
103
|
+
return {
|
|
104
|
+
suri: validateTypeRs.suri,
|
|
105
|
+
depth: validateTypeRs.depth,
|
|
106
|
+
derivationPath: derivePath,
|
|
107
|
+
parentAddress,
|
|
108
|
+
autoIndexes: validateTypeRs.autoIndexes
|
|
109
|
+
};
|
|
110
|
+
} else {
|
|
111
|
+
return {
|
|
112
|
+
depth: 1,
|
|
113
|
+
derivationPath: derivePath,
|
|
114
|
+
parentAddress,
|
|
115
|
+
suri
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
depth: 0,
|
|
122
|
+
parentAddress,
|
|
123
|
+
suri: suri
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @func findSoloNextDerive
|
|
129
|
+
* @return {NextDerivePair}
|
|
130
|
+
* */
|
|
131
|
+
export const findSoloNextDerive = parentAddress => {
|
|
132
|
+
var _deriveInfo$autoIndex;
|
|
133
|
+
let parentPair;
|
|
134
|
+
try {
|
|
135
|
+
parentPair = keyring.getPair(parentAddress);
|
|
136
|
+
} catch (e) {}
|
|
137
|
+
assert(parentPair, t('Unable to find account'));
|
|
138
|
+
const deriveInfo = getSoloDerivationInfo(parentPair.type, parentPair.meta);
|
|
139
|
+
const needChangeRoot = deriveInfo.depth > 0;
|
|
140
|
+
let rootPair;
|
|
141
|
+
if (needChangeRoot) {
|
|
142
|
+
try {
|
|
143
|
+
rootPair = keyring.getPair(parentPair.meta.parentAddress || '');
|
|
144
|
+
} catch (e) {}
|
|
145
|
+
} else {
|
|
146
|
+
rootPair = parentPair;
|
|
147
|
+
}
|
|
148
|
+
assert(rootPair, t('Unable to find parent account'));
|
|
149
|
+
const rootAddress = rootPair.address;
|
|
150
|
+
const currentDepth = deriveInfo.depth;
|
|
151
|
+
const currentIndex = (_deriveInfo$autoIndex = deriveInfo.autoIndexes) === null || _deriveInfo$autoIndex === void 0 ? void 0 : _deriveInfo$autoIndex[currentDepth - 1];
|
|
152
|
+
const pairs = keyring.getPairs();
|
|
153
|
+
const children = pairs.filter(p => p.meta.parentAddress === rootAddress);
|
|
154
|
+
const childrenMetadata = children.map(({
|
|
155
|
+
meta,
|
|
156
|
+
type
|
|
157
|
+
}) => getSoloDerivationInfo(type, meta)).filter(({
|
|
158
|
+
autoIndexes,
|
|
159
|
+
depth
|
|
160
|
+
}) => {
|
|
161
|
+
return depth === currentDepth + 1 && currentIndex === (autoIndexes === null || autoIndexes === void 0 ? void 0 : autoIndexes[currentDepth - 1]);
|
|
162
|
+
}).sort((a, b) => {
|
|
163
|
+
var _a$autoIndexes, _b$autoIndexes;
|
|
164
|
+
const aDeriveIndex = (_a$autoIndexes = a.autoIndexes) === null || _a$autoIndexes === void 0 ? void 0 : _a$autoIndexes[currentDepth];
|
|
165
|
+
const bDeriveIndex = (_b$autoIndexes = b.autoIndexes) === null || _b$autoIndexes === void 0 ? void 0 : _b$autoIndexes[currentDepth];
|
|
166
|
+
if (aDeriveIndex !== undefined && bDeriveIndex !== undefined) {
|
|
167
|
+
return aDeriveIndex - bDeriveIndex;
|
|
168
|
+
} else {
|
|
169
|
+
if (aDeriveIndex === undefined && bDeriveIndex === undefined) {
|
|
170
|
+
return 0;
|
|
171
|
+
} else {
|
|
172
|
+
return aDeriveIndex === undefined ? 1 : -1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
let index = currentDepth === 0 ? 1 : 0;
|
|
177
|
+
for (const {
|
|
178
|
+
autoIndexes,
|
|
179
|
+
suri
|
|
180
|
+
} of childrenMetadata) {
|
|
181
|
+
const _autoIndexes = autoIndexes;
|
|
182
|
+
const deriveIndex = _autoIndexes[currentDepth];
|
|
183
|
+
if (!suri || deriveIndex === undefined) {
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
if (deriveIndex === index) {
|
|
187
|
+
index++;
|
|
188
|
+
} else {
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const isSubstrate = SubstrateKeypairTypes.includes(parentPair.type);
|
|
193
|
+
const indexes = currentDepth > 0 ? deriveInfo.autoIndexes || [] : [];
|
|
194
|
+
indexes.push(index);
|
|
195
|
+
const suri = isSubstrate ? [deriveInfo.suri || '', index].join('//') : '//'.concat(indexes.join('//'));
|
|
196
|
+
return {
|
|
197
|
+
deriveIndex: index,
|
|
198
|
+
depth: currentDepth + 1,
|
|
199
|
+
derivationPath: parseUnifiedSuriToDerivationPath(suri, rootPair.type),
|
|
200
|
+
suri,
|
|
201
|
+
deriveAddress: rootAddress
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
export const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
205
|
+
var _parentPair$ton;
|
|
206
|
+
if (parentPair.isLocked) {
|
|
207
|
+
keyring.unlockPair(parentPair.address);
|
|
208
|
+
}
|
|
209
|
+
const isEvm = EthereumKeypairTypes.includes(parentPair.type);
|
|
210
|
+
const isTon = parentPair.type === 'ton';
|
|
211
|
+
const meta = {
|
|
212
|
+
name,
|
|
213
|
+
parentAddress: parentPair.address,
|
|
214
|
+
suri: suri,
|
|
215
|
+
derivationPath,
|
|
216
|
+
tonContractVersion: undefined
|
|
217
|
+
};
|
|
218
|
+
if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
|
|
219
|
+
meta.tonContractVersion = parentPair.ton.contractVersion;
|
|
220
|
+
}
|
|
221
|
+
if (derivationPath && (isEvm || isTon)) {
|
|
222
|
+
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : parentPair.ton.deriveCustom(derivationPath, meta);
|
|
223
|
+
} else {
|
|
224
|
+
return parentPair.substrate.derive(suri, meta);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
export const getSuri = (seed, type) => {
|
|
228
|
+
const extraPath = type ? getDerivePath(type)(0) : '';
|
|
229
|
+
return seed + (extraPath ? '/' + extraPath : '');
|
|
230
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AccountProxyMap, DeriveInfo, NextDerivePair } from '@subwallet/extension-base/types';
|
|
2
|
+
export declare const getUnifiedDerivationInfo: (suri?: string) => DeriveInfo;
|
|
3
|
+
/**
|
|
4
|
+
* @func findUnifiedNextDerive
|
|
5
|
+
* @return {NextDerivePair}
|
|
6
|
+
* */
|
|
7
|
+
export declare const findUnifiedNextDerive: (proxyId: string, accounts: AccountProxyMap) => NextDerivePair;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { AccountProxyType } from '@subwallet/extension-base/types';
|
|
5
|
+
import { validateUnifiedDerivationPath } from "../validate.js";
|
|
6
|
+
import { getSoloDerivationInfo } from "./solo.js";
|
|
7
|
+
export const getUnifiedDerivationInfo = suri => {
|
|
8
|
+
if (suri) {
|
|
9
|
+
const validateUnifiedRs = validateUnifiedDerivationPath(suri);
|
|
10
|
+
if (validateUnifiedRs) {
|
|
11
|
+
const {
|
|
12
|
+
autoIndexes,
|
|
13
|
+
depth
|
|
14
|
+
} = validateUnifiedRs;
|
|
15
|
+
return {
|
|
16
|
+
suri: suri,
|
|
17
|
+
depth,
|
|
18
|
+
autoIndexes
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
depth: 0,
|
|
24
|
+
suri
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @func findUnifiedNextDerive
|
|
30
|
+
* @return {NextDerivePair}
|
|
31
|
+
* */
|
|
32
|
+
export const findUnifiedNextDerive = (proxyId, accounts) => {
|
|
33
|
+
var _deriveInfo$autoIndex, _parentProxy$children;
|
|
34
|
+
const currentProxy = accounts[proxyId];
|
|
35
|
+
const parentProxyId = currentProxy.parentId || currentProxy.id;
|
|
36
|
+
const parentProxy = accounts[parentProxyId];
|
|
37
|
+
const deriveInfo = getUnifiedDerivationInfo(currentProxy.suri);
|
|
38
|
+
const currentDepth = deriveInfo.depth;
|
|
39
|
+
const currentIndex = (_deriveInfo$autoIndex = deriveInfo.autoIndexes) === null || _deriveInfo$autoIndex === void 0 ? void 0 : _deriveInfo$autoIndex[currentDepth - 1];
|
|
40
|
+
const children = ((_parentProxy$children = parentProxy.children) === null || _parentProxy$children === void 0 ? void 0 : _parentProxy$children.map(id => accounts[id])) || [];
|
|
41
|
+
const childrenMetadata = children.map(({
|
|
42
|
+
accountType,
|
|
43
|
+
accounts,
|
|
44
|
+
suri
|
|
45
|
+
}) => {
|
|
46
|
+
if (accountType === AccountProxyType.UNIFIED) {
|
|
47
|
+
return getUnifiedDerivationInfo(suri);
|
|
48
|
+
} else {
|
|
49
|
+
const account = accounts[0];
|
|
50
|
+
return getSoloDerivationInfo(account.type, account);
|
|
51
|
+
}
|
|
52
|
+
}).filter(({
|
|
53
|
+
autoIndexes,
|
|
54
|
+
depth
|
|
55
|
+
}) => {
|
|
56
|
+
if (depth !== currentDepth + 1) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (autoIndexes !== null && autoIndexes !== void 0 && autoIndexes.includes(undefined)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return currentIndex === (autoIndexes === null || autoIndexes === void 0 ? void 0 : autoIndexes[currentDepth - 1]);
|
|
63
|
+
}).sort((a, b) => {
|
|
64
|
+
var _a$autoIndexes, _b$autoIndexes;
|
|
65
|
+
const aDeriveIndex = (_a$autoIndexes = a.autoIndexes) === null || _a$autoIndexes === void 0 ? void 0 : _a$autoIndexes[currentDepth];
|
|
66
|
+
const bDeriveIndex = (_b$autoIndexes = b.autoIndexes) === null || _b$autoIndexes === void 0 ? void 0 : _b$autoIndexes[currentDepth];
|
|
67
|
+
if (aDeriveIndex !== undefined && bDeriveIndex !== undefined) {
|
|
68
|
+
return aDeriveIndex - bDeriveIndex;
|
|
69
|
+
} else {
|
|
70
|
+
if (aDeriveIndex === undefined && bDeriveIndex === undefined) {
|
|
71
|
+
return 0;
|
|
72
|
+
} else {
|
|
73
|
+
return aDeriveIndex === undefined ? 1 : -1;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
let index = currentDepth === 0 ? 1 : 0;
|
|
78
|
+
for (const {
|
|
79
|
+
autoIndexes,
|
|
80
|
+
suri
|
|
81
|
+
} of childrenMetadata) {
|
|
82
|
+
const _autoIndexes = autoIndexes;
|
|
83
|
+
const deriveIndex = _autoIndexes[currentDepth];
|
|
84
|
+
if (!suri || deriveIndex === undefined) {
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (deriveIndex === index) {
|
|
88
|
+
index++;
|
|
89
|
+
} else {
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const indexes = currentDepth > 0 ? deriveInfo.autoIndexes || [] : [];
|
|
94
|
+
indexes.push(index);
|
|
95
|
+
const suri = '//'.concat(indexes.join('//'));
|
|
96
|
+
return {
|
|
97
|
+
deriveIndex: index,
|
|
98
|
+
depth: currentDepth + 1,
|
|
99
|
+
suri,
|
|
100
|
+
deriveAddress: parentProxy.id
|
|
101
|
+
};
|
|
102
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DerivePathInfo, IDerivePathInfo_ } from '@subwallet/extension-base/types';
|
|
2
|
+
import { KeypairType, SubstrateKeypairType } from '@subwallet/keyring/types';
|
|
3
|
+
export declare const validateUnifiedDerivationPath: (raw: string) => DerivePathInfo | undefined;
|
|
4
|
+
export declare const validateEvmDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
5
|
+
export declare const validateTonDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
6
|
+
export declare const validateSr25519DerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
7
|
+
export declare const validateOtherSubstrateDerivationPath: (raw: string, type: Exclude<SubstrateKeypairType, 'sr25519'>) => IDerivePathInfo_ | undefined;
|
|
8
|
+
export declare const validateDerivationPath: (raw: string, type?: KeypairType) => DerivePathInfo | undefined;
|