@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
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { ALL_ACCOUNT_AUTH_TYPES } from '@subwallet/extension-base/constants';
|
|
4
5
|
import { _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
5
|
-
import {
|
|
6
|
+
import { DAPP_CONNECT_BOTH_TYPE_ACCOUNT_URL, PREDEFINED_CHAIN_DAPP_CHAIN_MAP, WEB_APP_URL } from '@subwallet/extension-base/services/request-service/constants';
|
|
6
7
|
import AuthorizeStore from '@subwallet/extension-base/stores/Authorize';
|
|
7
8
|
import { createPromiseHandler, getDomainFromUrl, stripUrl } from '@subwallet/extension-base/utils';
|
|
8
9
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
10
|
+
import { isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
9
11
|
import { BehaviorSubject } from 'rxjs';
|
|
10
12
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
11
13
|
const AUTH_URLS_KEY = 'authUrls';
|
|
@@ -22,27 +24,48 @@ export default class AuthRequestHandler {
|
|
|
22
24
|
this.keyringService = keyringService;
|
|
23
25
|
this.#requestService = requestService;
|
|
24
26
|
this.#chainService = chainService;
|
|
25
|
-
this.
|
|
27
|
+
this.migrateAuthUrlInfoToUnified().then(() => {
|
|
28
|
+
this.init().catch(console.error);
|
|
29
|
+
}).catch(console.error);
|
|
26
30
|
}
|
|
27
31
|
async init() {
|
|
28
32
|
const authList = await this.getAuthList();
|
|
29
33
|
let needUpdateAuthList = false;
|
|
30
|
-
Object.entries(authList).
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
34
|
+
const updatedAuthList = Object.entries(authList).reduce((acc, [key, value]) => {
|
|
35
|
+
const existKeyBothConnectAuthType = DAPP_CONNECT_BOTH_TYPE_ACCOUNT_URL.some(url_ => url_.includes(key));
|
|
36
|
+
if (existKeyBothConnectAuthType && (!value.accountAuthTypes || value.accountAuthTypes.length < 2)) {
|
|
37
|
+
value.accountAuthTypes = ['evm', 'substrate'];
|
|
33
38
|
needUpdateAuthList = true;
|
|
34
|
-
authList[key] = {
|
|
35
|
-
...value,
|
|
36
|
-
accountAuthType: 'both'
|
|
37
|
-
};
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
acc[key] = {
|
|
41
|
+
...value
|
|
42
|
+
};
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
if (needUpdateAuthList) {
|
|
46
|
+
this.setAuthorize(updatedAuthList);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async migrateAuthUrlInfoToUnified() {
|
|
50
|
+
const authList = await this.getAuthList();
|
|
51
|
+
let needUpdateAuthList = false;
|
|
52
|
+
const updatedAuthList = Object.entries(authList).reduce((acc, [key, value]) => {
|
|
53
|
+
if ('accountAuthType' in value) {
|
|
54
|
+
const oldValueStructure = value;
|
|
55
|
+
needUpdateAuthList = true;
|
|
56
|
+
value.accountAuthTypes = oldValueStructure.accountAuthType === 'both' ? ['substrate', 'evm'] : [oldValueStructure.accountAuthType || 'substrate'];
|
|
57
|
+
}
|
|
58
|
+
acc[key] = {
|
|
59
|
+
...value
|
|
60
|
+
};
|
|
61
|
+
return acc;
|
|
62
|
+
}, {});
|
|
40
63
|
if (needUpdateAuthList) {
|
|
41
|
-
this.setAuthorize(
|
|
64
|
+
this.setAuthorize(updatedAuthList);
|
|
42
65
|
}
|
|
43
66
|
}
|
|
44
67
|
getAddressList(value = false) {
|
|
45
|
-
const addressList = Object.keys(this.keyringService.
|
|
68
|
+
const addressList = Object.keys(this.keyringService.context.pairs);
|
|
46
69
|
return addressList.reduce((addressList, v) => ({
|
|
47
70
|
...addressList,
|
|
48
71
|
[v]: value
|
|
@@ -108,7 +131,7 @@ export default class AuthRequestHandler {
|
|
|
108
131
|
}
|
|
109
132
|
}
|
|
110
133
|
let chainInfo;
|
|
111
|
-
if (
|
|
134
|
+
if (options.accessType === 'evm') {
|
|
112
135
|
const evmChains = Object.values(chainInfoMaps).filter(_isChainEvmCompatible);
|
|
113
136
|
chainInfo = (defaultChain ? chainInfoMaps[defaultChain] : evmChains.find(chain => {
|
|
114
137
|
var _chainStateMap$chain$;
|
|
@@ -132,7 +155,6 @@ export default class AuthRequestHandler {
|
|
|
132
155
|
authCompleteV2 = (id, url, resolve, reject) => {
|
|
133
156
|
const isAllowedMap = this.getAddressList();
|
|
134
157
|
const complete = (result, cb, accounts) => {
|
|
135
|
-
var _this$getDAppChainInf;
|
|
136
158
|
const isAllowed = result === true;
|
|
137
159
|
let isCancelled = false;
|
|
138
160
|
if (!isAllowed && typeof result === 'object' && result.message === 'Cancelled') {
|
|
@@ -143,11 +165,12 @@ export default class AuthRequestHandler {
|
|
|
143
165
|
isAllowedMap[acc] = true;
|
|
144
166
|
});
|
|
145
167
|
} else {
|
|
146
|
-
|
|
147
|
-
|
|
168
|
+
Object.keys(isAllowedMap).forEach(address => {
|
|
169
|
+
isAllowedMap[address] = false;
|
|
170
|
+
});
|
|
148
171
|
}
|
|
149
172
|
const {
|
|
150
|
-
|
|
173
|
+
accountAuthTypes,
|
|
151
174
|
idStr,
|
|
152
175
|
request: {
|
|
153
176
|
allowedAccounts,
|
|
@@ -155,21 +178,36 @@ export default class AuthRequestHandler {
|
|
|
155
178
|
},
|
|
156
179
|
url
|
|
157
180
|
} = this.#authRequestsV2[id];
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
181
|
+
|
|
182
|
+
// Note: accountAuthTypes represents the accountAuthType of this request
|
|
183
|
+
// allowedAccounts is a list of connected accounts that exist for this origin during this request.
|
|
184
|
+
|
|
185
|
+
if (accountAuthTypes.length !== ALL_ACCOUNT_AUTH_TYPES.length) {
|
|
186
|
+
const backupAllowed = (allowedAccounts || []).filter(a => {
|
|
187
|
+
if (isEthereumAddress(a) && !accountAuthTypes.includes('evm')) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (isSubstrateAddress(a) && !accountAuthTypes.includes('substrate')) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
if (isTonAddress(a) && !accountAuthTypes.includes('ton')) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
return false;
|
|
163
197
|
});
|
|
164
198
|
backupAllowed.forEach(acc => {
|
|
165
199
|
isAllowedMap[acc] = true;
|
|
166
200
|
});
|
|
167
201
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
202
|
+
let defaultEvmNetworkKey;
|
|
203
|
+
if (accountAuthTypes.includes('evm')) {
|
|
204
|
+
const chainInfo = this.getDAppChainInfo({
|
|
205
|
+
accessType: 'evm',
|
|
206
|
+
autoActive: true,
|
|
207
|
+
url
|
|
208
|
+
});
|
|
209
|
+
defaultEvmNetworkKey = chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.slug;
|
|
210
|
+
}
|
|
173
211
|
this.getAuthorize(value => {
|
|
174
212
|
let authorizeList = {};
|
|
175
213
|
if (value) {
|
|
@@ -191,7 +229,7 @@ export default class AuthRequestHandler {
|
|
|
191
229
|
isAllowedMap,
|
|
192
230
|
origin,
|
|
193
231
|
url,
|
|
194
|
-
|
|
232
|
+
accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
|
|
195
233
|
currentEvmNetworkKey: existed ? existed.currentEvmNetworkKey : defaultEvmNetworkKey
|
|
196
234
|
};
|
|
197
235
|
this.setAuthorize(authorizeList, () => {
|
|
@@ -221,9 +259,8 @@ export default class AuthRequestHandler {
|
|
|
221
259
|
async authorizeUrlV2(url, request) {
|
|
222
260
|
let authList = await this.getAuthList();
|
|
223
261
|
const idStr = stripUrl(url);
|
|
224
|
-
const
|
|
225
|
-
let
|
|
226
|
-
request.accountAuthType = accountAuthType;
|
|
262
|
+
const isAllowedDappConnectBothType = !!DAPP_CONNECT_BOTH_TYPE_ACCOUNT_URL.find(url_ => url.includes(url_));
|
|
263
|
+
let accountAuthTypes = [...new Set(isAllowedDappConnectBothType ? ['evm', 'substrate'] : request.accountAuthTypes || ['substrate'])];
|
|
227
264
|
if (!authList) {
|
|
228
265
|
authList = {};
|
|
229
266
|
}
|
|
@@ -234,7 +271,10 @@ export default class AuthRequestHandler {
|
|
|
234
271
|
reject,
|
|
235
272
|
resolve
|
|
236
273
|
} = promiseHandler;
|
|
237
|
-
const isExistedAuthBothBefore = Object.entries(this.authorizeUrlSubject.value).find(([key, data]) =>
|
|
274
|
+
const isExistedAuthBothBefore = Object.entries(this.authorizeUrlSubject.value).find(([key, data]) => {
|
|
275
|
+
var _data$accountAuthType;
|
|
276
|
+
return key === idStr && ((_data$accountAuthType = data.accountAuthTypes) === null || _data$accountAuthType === void 0 ? void 0 : _data$accountAuthType.length) === ALL_ACCOUNT_AUTH_TYPES.length;
|
|
277
|
+
});
|
|
238
278
|
if (isExistedAuthBothBefore) {
|
|
239
279
|
return true;
|
|
240
280
|
}
|
|
@@ -250,9 +290,9 @@ export default class AuthRequestHandler {
|
|
|
250
290
|
const mergeKeys = [];
|
|
251
291
|
Object.entries(this.#authRequestsV2).forEach(([key, _request]) => {
|
|
252
292
|
if (_request.idStr === idStr) {
|
|
253
|
-
if (
|
|
254
|
-
|
|
255
|
-
|
|
293
|
+
if (accountAuthTypes && _request.accountAuthTypes) {
|
|
294
|
+
const filteredAccountAuthTypes = new Set([..._request.accountAuthTypes, ...accountAuthTypes]);
|
|
295
|
+
accountAuthTypes = [...filteredAccountAuthTypes];
|
|
256
296
|
}
|
|
257
297
|
mergeKeys.push(key);
|
|
258
298
|
}
|
|
@@ -267,8 +307,8 @@ export default class AuthRequestHandler {
|
|
|
267
307
|
});
|
|
268
308
|
}
|
|
269
309
|
const existedAuth = authList[idStr];
|
|
270
|
-
const existedAccountAuthType = existedAuth === null || existedAuth === void 0 ? void 0 : existedAuth.
|
|
271
|
-
const confirmAnotherType = existedAccountAuthType
|
|
310
|
+
const existedAccountAuthType = existedAuth === null || existedAuth === void 0 ? void 0 : existedAuth.accountAuthTypes;
|
|
311
|
+
const confirmAnotherType = !existedAccountAuthType || accountAuthTypes.some(type => !existedAccountAuthType.includes(type));
|
|
272
312
|
if (request.reConfirm && existedAuth) {
|
|
273
313
|
request.origin = existedAuth.origin;
|
|
274
314
|
}
|
|
@@ -281,11 +321,16 @@ export default class AuthRequestHandler {
|
|
|
281
321
|
}
|
|
282
322
|
request.allowedAccounts = Object.entries(existedAuth.isAllowedMap).map(([address, allowed]) => allowed ? address : '').filter(item => item !== '');
|
|
283
323
|
let allowedListByRequestType = [...request.allowedAccounts];
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
324
|
+
allowedListByRequestType = accountAuthTypes.reduce((list, accountAuthType) => {
|
|
325
|
+
if (accountAuthType === 'evm') {
|
|
326
|
+
list.push(...allowedListByRequestType.filter(a => isEthereumAddress(a)));
|
|
327
|
+
} else if (accountAuthType === 'substrate') {
|
|
328
|
+
list.push(...allowedListByRequestType.filter(a => isSubstrateAddress(a)));
|
|
329
|
+
} else if (accountAuthType === 'ton') {
|
|
330
|
+
list.push(...allowedListByRequestType.filter(a => isTonAddress(a)));
|
|
331
|
+
}
|
|
332
|
+
return list;
|
|
333
|
+
}, []);
|
|
289
334
|
if (!confirmAnotherType && !request.reConfirm && allowedListByRequestType.length !== 0) {
|
|
290
335
|
// Prevent appear confirmation popup
|
|
291
336
|
return false;
|
|
@@ -304,7 +349,7 @@ export default class AuthRequestHandler {
|
|
|
304
349
|
isAllowedMap,
|
|
305
350
|
origin,
|
|
306
351
|
url,
|
|
307
|
-
|
|
352
|
+
accountAuthTypes: ALL_ACCOUNT_AUTH_TYPES
|
|
308
353
|
};
|
|
309
354
|
this.setAuthorize(authList);
|
|
310
355
|
return true;
|
|
@@ -314,9 +359,12 @@ export default class AuthRequestHandler {
|
|
|
314
359
|
...this.authCompleteV2(id, url, resolve, reject),
|
|
315
360
|
id,
|
|
316
361
|
idStr,
|
|
317
|
-
request
|
|
362
|
+
request: {
|
|
363
|
+
...request,
|
|
364
|
+
accountAuthTypes
|
|
365
|
+
},
|
|
318
366
|
url,
|
|
319
|
-
|
|
367
|
+
accountAuthTypes: accountAuthTypes || ['substrate']
|
|
320
368
|
};
|
|
321
369
|
this.updateIconAuthV2();
|
|
322
370
|
if (Object.keys(this.#authRequestsV2).length < 2 && !(mergeKeys.length > 0 && mergeKeys[mergeKeys.length - 1] !== id)) {
|
|
@@ -103,11 +103,10 @@ export default class EvmRequestHandler {
|
|
|
103
103
|
}
|
|
104
104
|
async signMessage(confirmation) {
|
|
105
105
|
const {
|
|
106
|
-
|
|
106
|
+
address,
|
|
107
107
|
payload,
|
|
108
108
|
type
|
|
109
109
|
} = confirmation.payload;
|
|
110
|
-
const address = account.address;
|
|
111
110
|
const pair = keyring.getPair(address);
|
|
112
111
|
if (pair.isLocked) {
|
|
113
112
|
keyring.unlockPair(pair.address);
|
|
@@ -119,7 +118,7 @@ export default class EvmRequestHandler {
|
|
|
119
118
|
case 'eth_signTypedData_v1':
|
|
120
119
|
case 'eth_signTypedData_v3':
|
|
121
120
|
case 'eth_signTypedData_v4':
|
|
122
|
-
return await pair.
|
|
121
|
+
return await pair.evm.signMessage(payload, type);
|
|
123
122
|
default:
|
|
124
123
|
throw new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, t('Unsupported action'));
|
|
125
124
|
}
|
|
@@ -197,7 +196,7 @@ export default class EvmRequestHandler {
|
|
|
197
196
|
if (pair.isLocked) {
|
|
198
197
|
keyring.unlockPair(pair.address);
|
|
199
198
|
}
|
|
200
|
-
return pair.
|
|
199
|
+
return pair.evm.signTransaction(tx);
|
|
201
200
|
}
|
|
202
201
|
async decorateResult(t, request, result) {
|
|
203
202
|
if (result.payload === '') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
2
2
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
3
3
|
import { SignRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
4
4
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -12,7 +12,7 @@ export default class SubstrateRequestHandler {
|
|
|
12
12
|
private updateIconSign;
|
|
13
13
|
private signComplete;
|
|
14
14
|
get numSubstrateRequests(): number;
|
|
15
|
-
sign(url: string, request: RequestSign,
|
|
15
|
+
sign(url: string, request: RequestSign, _id?: string): Promise<ResponseSigning>;
|
|
16
16
|
signTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON): Promise<ResponseSigning>;
|
|
17
17
|
resetWallet(): void;
|
|
18
18
|
}
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import RequestExtrinsicSign from '@subwallet/extension-base/background/RequestExtrinsicSign';
|
|
5
5
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
6
6
|
import { isInternalRequest } from '@subwallet/extension-base/utils/request';
|
|
7
|
-
import keyring from '@subwallet/ui-keyring';
|
|
8
7
|
import { BehaviorSubject } from 'rxjs';
|
|
9
8
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
10
9
|
export default class SubstrateRequestHandler {
|
|
@@ -21,12 +20,12 @@ export default class SubstrateRequestHandler {
|
|
|
21
20
|
}
|
|
22
21
|
get allSubstrateRequests() {
|
|
23
22
|
return Object.values(this.#substrateRequests).map(({
|
|
24
|
-
|
|
23
|
+
address,
|
|
25
24
|
id,
|
|
26
25
|
request,
|
|
27
26
|
url
|
|
28
27
|
}) => ({
|
|
29
|
-
|
|
28
|
+
address,
|
|
30
29
|
id,
|
|
31
30
|
request,
|
|
32
31
|
url,
|
|
@@ -57,7 +56,7 @@ export default class SubstrateRequestHandler {
|
|
|
57
56
|
get numSubstrateRequests() {
|
|
58
57
|
return Object.keys(this.#substrateRequests).length;
|
|
59
58
|
}
|
|
60
|
-
async sign(url, request,
|
|
59
|
+
async sign(url, request, _id) {
|
|
61
60
|
const id = _id || getId();
|
|
62
61
|
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
63
62
|
if (isAlwaysRequired) {
|
|
@@ -66,7 +65,7 @@ export default class SubstrateRequestHandler {
|
|
|
66
65
|
return new Promise((resolve, reject) => {
|
|
67
66
|
this.#substrateRequests[id] = {
|
|
68
67
|
...this.signComplete(id, resolve, reject),
|
|
69
|
-
|
|
68
|
+
address: request.payload.address,
|
|
70
69
|
id,
|
|
71
70
|
request,
|
|
72
71
|
url
|
|
@@ -81,14 +80,9 @@ export default class SubstrateRequestHandler {
|
|
|
81
80
|
this.#requestService.keyringService.lock();
|
|
82
81
|
}
|
|
83
82
|
return new Promise((resolve, reject) => {
|
|
84
|
-
const pair = keyring.getPair(address);
|
|
85
|
-
const account = {
|
|
86
|
-
address: pair.address,
|
|
87
|
-
...pair.meta
|
|
88
|
-
};
|
|
89
83
|
this.#substrateRequests[id] = {
|
|
90
84
|
...this.signComplete(id, resolve, reject),
|
|
91
|
-
|
|
85
|
+
address,
|
|
92
86
|
id,
|
|
93
87
|
request: new RequestExtrinsicSign(payload),
|
|
94
88
|
url: url
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ConfirmationDefinitionsTon, ConfirmationsQueueItemOptions, ConfirmationsQueueTon, ConfirmationTypeTon, RequestConfirmationCompleteTon } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
3
|
+
import { BehaviorSubject } from 'rxjs';
|
|
4
|
+
export default class TonRequestHandler {
|
|
5
|
+
#private;
|
|
6
|
+
private readonly confirmationsQueueSubjectTon;
|
|
7
|
+
private readonly confirmationsPromiseMap;
|
|
8
|
+
constructor(requestService: RequestService);
|
|
9
|
+
get numTonRequests(): number;
|
|
10
|
+
getConfirmationsQueueSubjectTon(): BehaviorSubject<ConfirmationsQueueTon>;
|
|
11
|
+
addConfirmationTon<CT extends ConfirmationTypeTon>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsTon[CT][0]['payload'], // todo: messages <-> payload
|
|
12
|
+
options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsTon[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsTon[CT][1]>;
|
|
13
|
+
completeConfirmationTon(request: RequestConfirmationCompleteTon): Promise<boolean>;
|
|
14
|
+
private decorateResult;
|
|
15
|
+
private signTransactionTon;
|
|
16
|
+
resetWallet(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { isInternalRequest } from '@subwallet/extension-base/utils/request';
|
|
5
|
+
import { keyring } from '@subwallet/ui-keyring';
|
|
6
|
+
import { Cell } from '@ton/core';
|
|
7
|
+
import { t } from 'i18next';
|
|
8
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
import { u8aToHex } from '@polkadot/util';
|
|
10
|
+
import { logger as createLogger } from '@polkadot/util/logger';
|
|
11
|
+
export default class TonRequestHandler {
|
|
12
|
+
#requestService;
|
|
13
|
+
#logger;
|
|
14
|
+
confirmationsQueueSubjectTon = new BehaviorSubject({
|
|
15
|
+
tonSignatureRequest: {},
|
|
16
|
+
tonSendTransactionRequest: {},
|
|
17
|
+
tonWatchTransactionRequest: {}
|
|
18
|
+
});
|
|
19
|
+
confirmationsPromiseMap = {};
|
|
20
|
+
constructor(requestService) {
|
|
21
|
+
this.#requestService = requestService;
|
|
22
|
+
this.#logger = createLogger('TonRequestHandler');
|
|
23
|
+
}
|
|
24
|
+
get numTonRequests() {
|
|
25
|
+
let count = 0;
|
|
26
|
+
Object.values(this.confirmationsQueueSubjectTon.getValue()).forEach(x => {
|
|
27
|
+
count += Object.keys(x).length;
|
|
28
|
+
});
|
|
29
|
+
return count;
|
|
30
|
+
}
|
|
31
|
+
getConfirmationsQueueSubjectTon() {
|
|
32
|
+
return this.confirmationsQueueSubjectTon;
|
|
33
|
+
}
|
|
34
|
+
async addConfirmationTon(id, url, type, payload,
|
|
35
|
+
// todo: messages <-> payload
|
|
36
|
+
options = {}, validator) {
|
|
37
|
+
const confirmations = this.confirmationsQueueSubjectTon.getValue();
|
|
38
|
+
const confirmationType = confirmations[type];
|
|
39
|
+
const payloadJson = JSON.stringify({});
|
|
40
|
+
const isInternal = isInternalRequest(url);
|
|
41
|
+
if (['tonSendTransactionRequest', 'tonSignatureRequest'].includes(type)) {
|
|
42
|
+
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
43
|
+
if (isAlwaysRequired) {
|
|
44
|
+
this.#requestService.keyringService.lock();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Check duplicate request
|
|
49
|
+
const duplicated = Object.values(confirmationType).find(c => c.url === url && c.payloadJson === payloadJson);
|
|
50
|
+
if (duplicated) {
|
|
51
|
+
throw new Error('Ton duplicate request'); // update this message.
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
confirmationType[id] = {
|
|
55
|
+
id,
|
|
56
|
+
url,
|
|
57
|
+
isInternal,
|
|
58
|
+
payload,
|
|
59
|
+
payloadJson,
|
|
60
|
+
...options
|
|
61
|
+
};
|
|
62
|
+
const promise = new Promise((resolve, reject) => {
|
|
63
|
+
this.confirmationsPromiseMap[id] = {
|
|
64
|
+
validator: validator,
|
|
65
|
+
resolver: {
|
|
66
|
+
resolve: resolve,
|
|
67
|
+
reject: reject
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
this.confirmationsQueueSubjectTon.next(confirmations);
|
|
72
|
+
if (!isInternal) {
|
|
73
|
+
this.#requestService.popupOpen();
|
|
74
|
+
}
|
|
75
|
+
this.#requestService.updateIconV2();
|
|
76
|
+
return promise;
|
|
77
|
+
}
|
|
78
|
+
async completeConfirmationTon(request) {
|
|
79
|
+
const confirmations = this.confirmationsQueueSubjectTon.getValue();
|
|
80
|
+
for (const ct in request) {
|
|
81
|
+
const type = ct;
|
|
82
|
+
const result = request[type];
|
|
83
|
+
const {
|
|
84
|
+
id
|
|
85
|
+
} = result;
|
|
86
|
+
const {
|
|
87
|
+
resolver,
|
|
88
|
+
validator
|
|
89
|
+
} = this.confirmationsPromiseMap[id];
|
|
90
|
+
const confirmation = confirmations[type][id];
|
|
91
|
+
if (!resolver || !confirmation) {
|
|
92
|
+
this.#logger.error(t('Unable to proceed. Please try again'), type, id);
|
|
93
|
+
throw new Error(t('Unable to proceed. Please try again'));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Fill signature for some special type
|
|
97
|
+
await this.decorateResult(type, confirmation, result);
|
|
98
|
+
|
|
99
|
+
// Validate response from confirmation popup some info like password, response format....
|
|
100
|
+
const error = validator && validator(result);
|
|
101
|
+
if (error) {
|
|
102
|
+
resolver.reject(error);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Delete confirmations from queue
|
|
106
|
+
delete this.confirmationsPromiseMap[id];
|
|
107
|
+
delete confirmations[type][id];
|
|
108
|
+
this.confirmationsQueueSubjectTon.next(confirmations);
|
|
109
|
+
|
|
110
|
+
// Update icon, and close queue
|
|
111
|
+
this.#requestService.updateIconV2(this.#requestService.numAllRequests === 0);
|
|
112
|
+
resolver.resolve(result);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// TODO: Review later
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
async decorateResult(t, request, result) {
|
|
119
|
+
if (result.payload === '') {
|
|
120
|
+
if (t === 'tonSignatureRequest') {
|
|
121
|
+
// result.payload = await this.signMessage(request as ConfirmationDefinitions['evmSignatureRequest'][0]);
|
|
122
|
+
} else if (t === 'tonSendTransactionRequest') {
|
|
123
|
+
result.payload = this.signTransactionTon(request);
|
|
124
|
+
}
|
|
125
|
+
if (t === 'tonSignatureRequest' || t === 'tonSendTransactionRequest') {
|
|
126
|
+
const isAlwaysRequired = await this.#requestService.settingService.isAlwaysRequired;
|
|
127
|
+
if (isAlwaysRequired) {
|
|
128
|
+
this.#requestService.keyringService.lock();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
signTransactionTon(confirmation) {
|
|
134
|
+
const transaction = confirmation.payload;
|
|
135
|
+
const {
|
|
136
|
+
from,
|
|
137
|
+
messagePayload
|
|
138
|
+
} = transaction;
|
|
139
|
+
const pair = keyring.getPair(from);
|
|
140
|
+
if (pair.isLocked) {
|
|
141
|
+
keyring.unlockPair(pair.address);
|
|
142
|
+
}
|
|
143
|
+
const messages = Cell.fromBase64(messagePayload);
|
|
144
|
+
const signedTransaction = pair.ton.sign(messages);
|
|
145
|
+
return u8aToHex(Uint8Array.from(signedTransaction));
|
|
146
|
+
}
|
|
147
|
+
resetWallet() {
|
|
148
|
+
const confirmations = this.confirmationsQueueSubjectTon.getValue();
|
|
149
|
+
for (const [type, requests] of Object.entries(confirmations)) {
|
|
150
|
+
for (const confirmation of Object.values(requests)) {
|
|
151
|
+
const {
|
|
152
|
+
id
|
|
153
|
+
} = confirmation;
|
|
154
|
+
const {
|
|
155
|
+
resolver
|
|
156
|
+
} = this.confirmationsPromiseMap[id];
|
|
157
|
+
if (!resolver || !confirmation) {
|
|
158
|
+
console.error('Not found confirmation', type, id);
|
|
159
|
+
} else {
|
|
160
|
+
resolver.reject(new Error('Reset wallet'));
|
|
161
|
+
}
|
|
162
|
+
delete this.confirmationsPromiseMap[id];
|
|
163
|
+
delete confirmations[type][id];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
this.confirmationsQueueSubjectTon.next(confirmations);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationType, RequestConfirmationComplete } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
-
import { AccountAuthType,
|
|
1
|
+
import { AuthRequestV2, ConfirmationDefinitions, ConfirmationDefinitionsTon, ConfirmationsQueue, ConfirmationsQueueItemOptions, ConfirmationsQueueTon, ConfirmationType, ConfirmationTypeTon, RequestConfirmationComplete, RequestConfirmationCompleteTon } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { AccountAuthType, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestSign, ResponseSigning, SigningRequest } from '@subwallet/extension-base/background/types';
|
|
3
3
|
import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
4
4
|
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
5
5
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
@@ -43,14 +43,19 @@ export default class RequestService {
|
|
|
43
43
|
ensureUrlAuthorizedV2(url: string): Promise<boolean>;
|
|
44
44
|
get signSubject(): BehaviorSubject<SigningRequest[]>;
|
|
45
45
|
get allSubstrateRequests(): SigningRequest[];
|
|
46
|
-
sign(url: string, request: RequestSign,
|
|
46
|
+
sign(url: string, request: RequestSign, id?: string): Promise<ResponseSigning>;
|
|
47
47
|
get numSubstrateRequests(): number;
|
|
48
48
|
get numEvmRequests(): number;
|
|
49
|
+
get numTonRequests(): number;
|
|
49
50
|
get confirmationsQueueSubject(): BehaviorSubject<ConfirmationsQueue>;
|
|
51
|
+
get confirmationsQueueSubjectTon(): BehaviorSubject<ConfirmationsQueueTon>;
|
|
50
52
|
getSignRequest(id: string): import("./types").SignRequest | undefined;
|
|
51
53
|
signInternalTransaction(id: string, address: string, url: string, payload: SignerPayloadJSON): Promise<ResponseSigning>;
|
|
52
54
|
addConfirmation<CT extends ConfirmationType>(id: string, url: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): Promise<ConfirmationDefinitions[CT][1]>;
|
|
55
|
+
addConfirmationTon<CT extends ConfirmationTypeTon>(id: string, url: string, type: CT, payload: ConfirmationDefinitionsTon[CT][0]['payload'], // todo: messages <-> payload
|
|
56
|
+
options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitionsTon[CT][1]) => Error | undefined): Promise<ConfirmationDefinitionsTon[CT][1]>;
|
|
53
57
|
completeConfirmation(request: RequestConfirmationComplete): Promise<boolean>;
|
|
58
|
+
completeConfirmationTon(request: RequestConfirmationCompleteTon): Promise<boolean>;
|
|
54
59
|
updateConfirmation<CT extends ConfirmationType>(id: string, type: CT, payload: ConfirmationDefinitions[CT][0]['payload'], options?: ConfirmationsQueueItemOptions, validator?: (input: ConfirmationDefinitions[CT][1]) => Error | undefined): void;
|
|
55
60
|
getConnectWCRequest(id: string): import("@subwallet/extension-base/services/wallet-connect-service/types").RequestWalletConnectSession;
|
|
56
61
|
get connectWCSubject(): BehaviorSubject<WalletConnectSessionRequest[]>;
|