@subwallet/extension-base 1.3.40-0 → 1.3.42-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 +121 -4
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/cjs/background/KoniTypes.js +20 -1
- package/cjs/background/errors/BitcoinProviderError.js +54 -0
- package/cjs/constants/bitcoin.js +22 -0
- package/cjs/constants/environment.js +4 -2
- package/cjs/constants/index.js +16 -1
- package/cjs/core/logic-validation/recipientAddress.js +9 -0
- package/cjs/core/logic-validation/transfer.js +25 -5
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +15 -1
- package/cjs/koni/background/handlers/Extension.js +96 -41
- package/cjs/koni/background/handlers/State.js +52 -11
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
- package/cjs/services/balance-service/index.js +32 -4
- package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
- package/cjs/services/balance-service/transfer/token.js +2 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +15 -9
- package/cjs/services/balance-service/transfer/xcm/utils.js +12 -14
- package/cjs/services/base/types.js +2 -0
- package/cjs/services/chain-service/constants.js +18 -6
- package/cjs/services/chain-service/handler/CardanoApi.js +25 -35
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
- package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/cjs/services/chain-service/index.js +27 -3
- package/cjs/services/chain-service/utils/index.js +57 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +4 -38
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/fee-service/service.js +8 -3
- package/cjs/services/hiro-service/index.js +96 -0
- package/cjs/services/hiro-service/utils/index.js +85 -0
- package/cjs/services/history-service/bitcoin-history.js +58 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/cjs/services/history-service/index.js +41 -3
- package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +440 -0
- package/cjs/services/request-service/index.js +29 -3
- package/cjs/services/rune-service/index.js +105 -0
- package/cjs/services/swap-service/handler/chainflip-handler.js +29 -18
- package/cjs/services/swap-service/handler/kyber-handler.js +5 -9
- package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -7
- package/cjs/services/swap-service/handler/uniswap-handler.js +5 -12
- package/cjs/services/swap-service/utils.js +46 -37
- package/cjs/services/transaction-service/helpers/index.js +7 -1
- package/cjs/services/transaction-service/index.js +136 -15
- package/cjs/services/transaction-service/utils.js +6 -3
- package/cjs/strategy/api-request-strategy/context/base.js +31 -0
- package/cjs/strategy/api-request-strategy/index.js +90 -0
- package/cjs/strategy/api-request-strategy/types.js +1 -0
- package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
- package/cjs/types/account/info/keyring.js +1 -1
- package/cjs/types/bitcoin.js +24 -0
- package/cjs/types/environment.js +19 -0
- package/cjs/types/fee/bitcoin.js +1 -0
- package/cjs/types/fee/index.js +11 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/account/analyze.js +3 -3
- package/cjs/utils/account/common.js +16 -6
- package/cjs/utils/account/derive/info/solo.js +68 -19
- package/cjs/utils/account/derive/info/unified.js +2 -0
- package/cjs/utils/account/derive/validate.js +70 -2
- package/cjs/utils/account/transform.js +11 -5
- package/cjs/utils/bitcoin/common.js +98 -0
- package/cjs/utils/bitcoin/fee.js +21 -0
- package/cjs/utils/bitcoin/index.js +38 -0
- package/cjs/utils/bitcoin/utxo-management.js +281 -0
- package/cjs/utils/environment.js +30 -2
- package/cjs/utils/fee/transfer.js +48 -0
- package/cjs/utils/index.js +15 -1
- package/constants/bitcoin.d.ts +3 -0
- package/constants/bitcoin.js +13 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- package/constants/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/core/logic-validation/recipientAddress.js +10 -1
- package/core/logic-validation/transfer.d.ts +2 -2
- package/core/logic-validation/transfer.js +27 -7
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +15 -2
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +95 -42
- package/koni/background/handlers/State.d.ts +7 -3
- package/koni/background/handlers/State.js +52 -12
- package/package.json +149 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
- package/services/balance-service/helpers/subscribe/evm.js +6 -1
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +20 -8
- package/services/balance-service/index.d.ts +2 -0
- package/services/balance-service/index.js +32 -4
- package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
- package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
- package/services/balance-service/transfer/token.js +2 -0
- package/services/balance-service/transfer/xcm/index.js +15 -9
- package/services/balance-service/transfer/xcm/utils.d.ts +2 -0
- package/services/balance-service/transfer/xcm/utils.js +12 -14
- package/services/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/chain-service/constants.d.ts +7 -0
- package/services/chain-service/constants.js +12 -5
- package/services/chain-service/handler/CardanoApi.d.ts +1 -5
- package/services/chain-service/handler/CardanoApi.js +26 -34
- package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
- package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
- package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +31 -5
- package/services/chain-service/types.d.ts +20 -0
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +50 -4
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/native-staking/tao.d.ts +0 -11
- package/services/earning-service/handlers/native-staking/tao.js +4 -24
- package/services/event-service/index.d.ts +3 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +3 -0
- package/services/fee-service/service.js +8 -3
- package/services/hiro-service/index.d.ts +17 -0
- package/services/hiro-service/index.js +88 -0
- package/services/hiro-service/utils/index.d.ts +6 -0
- package/services/hiro-service/utils/index.js +72 -0
- package/services/history-service/bitcoin-history.d.ts +4 -0
- package/services/history-service/bitcoin-history.js +52 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
- package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/services/history-service/index.d.ts +1 -0
- package/services/history-service/index.js +42 -4
- package/services/keyring-service/context/handlers/Derive.js +2 -2
- package/services/keyring-service/context/handlers/Migration.js +2 -2
- package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +23 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +427 -0
- package/services/request-service/index.d.ts +9 -2
- package/services/request-service/index.js +25 -3
- package/services/rune-service/index.d.ts +17 -0
- package/services/rune-service/index.js +97 -0
- package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
- package/services/swap-service/handler/chainflip-handler.js +25 -13
- package/services/swap-service/handler/kyber-handler.d.ts +0 -1
- package/services/swap-service/handler/kyber-handler.js +5 -8
- package/services/swap-service/handler/simpleswap-handler.d.ts +0 -1
- package/services/swap-service/handler/simpleswap-handler.js +4 -6
- package/services/swap-service/handler/uniswap-handler.js +6 -13
- package/services/swap-service/utils.d.ts +0 -13
- package/services/swap-service/utils.js +46 -34
- package/services/transaction-service/helpers/index.d.ts +3 -1
- package/services/transaction-service/helpers/index.js +5 -0
- package/services/transaction-service/index.d.ts +3 -5
- package/services/transaction-service/index.js +135 -16
- package/services/transaction-service/types.d.ts +12 -2
- package/services/transaction-service/utils.js +7 -4
- package/strategy/api-request-strategy/context/base.d.ts +15 -0
- package/strategy/api-request-strategy/context/base.js +24 -0
- package/strategy/api-request-strategy/index.d.ts +15 -0
- package/strategy/api-request-strategy/index.js +83 -0
- package/strategy/api-request-strategy/types.d.ts +22 -0
- package/strategy/api-request-strategy/types.js +1 -0
- package/strategy/api-request-strategy/utils/index.d.ts +2 -0
- package/strategy/api-request-strategy/utils/index.js +23 -0
- package/types/account/info/keyring.d.ts +1 -1
- package/types/account/info/keyring.js +1 -1
- package/types/balance/index.d.ts +4 -1
- package/types/balance/transfer.d.ts +17 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/environment.d.ts +9 -0
- package/types/environment.js +13 -0
- package/types/fee/base.d.ts +4 -1
- package/types/fee/bitcoin.d.ts +18 -0
- package/types/fee/bitcoin.js +1 -0
- package/types/fee/index.d.ts +1 -0
- package/types/fee/index.js +2 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account/analyze.js +4 -4
- package/utils/account/common.d.ts +7 -8
- package/utils/account/common.js +16 -6
- package/utils/account/derive/info/solo.js +70 -21
- package/utils/account/derive/info/unified.js +2 -0
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +68 -1
- package/utils/account/transform.d.ts +1 -1
- package/utils/account/transform.js +11 -5
- package/utils/bitcoin/common.d.ts +22 -0
- package/utils/bitcoin/common.js +88 -0
- package/utils/bitcoin/fee.d.ts +2 -0
- package/utils/bitcoin/fee.js +14 -0
- package/utils/bitcoin/index.d.ts +3 -0
- package/utils/bitcoin/index.js +6 -0
- package/utils/bitcoin/utxo-management.d.ts +33 -0
- package/utils/bitcoin/utxo-management.js +266 -0
- package/utils/environment.d.ts +2 -0
- package/utils/environment.js +27 -1
- package/utils/fee/transfer.d.ts +3 -1
- package/utils/fee/transfer.js +47 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +6 -3
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { SWTransactionBase } from '@subwallet/extension-base/services/transaction-service/types';
|
|
2
2
|
import { CurrentAccountInfo } from '@subwallet/extension-base/types';
|
|
3
3
|
export interface EventRegistry {
|
|
4
|
+
'general.init': [boolean];
|
|
5
|
+
'general.start': [boolean];
|
|
6
|
+
'general.start_full': [boolean];
|
|
4
7
|
'general.sleep': [boolean];
|
|
5
8
|
'general.wakeup': [boolean];
|
|
6
9
|
'crypto.ready': [boolean];
|
|
@@ -10,7 +10,8 @@ export default class FeeService {
|
|
|
10
10
|
evm: {},
|
|
11
11
|
substrate: {},
|
|
12
12
|
ton: {},
|
|
13
|
-
cardano: {}
|
|
13
|
+
cardano: {},
|
|
14
|
+
bitcoin: {}
|
|
14
15
|
};
|
|
15
16
|
constructor(state) {
|
|
16
17
|
this.state = state;
|
|
@@ -101,10 +102,9 @@ export default class FeeService {
|
|
|
101
102
|
if (cancel) {
|
|
102
103
|
clearInterval(interval);
|
|
103
104
|
} else {
|
|
104
|
-
const api = this.state.getEvmApi(chain);
|
|
105
|
-
|
|
106
105
|
// TODO: Handle case type === evm and not have api
|
|
107
106
|
if (type === 'evm') {
|
|
107
|
+
const api = this.state.getEvmApi(chain);
|
|
108
108
|
if (api) {
|
|
109
109
|
calculateGasFeeParams(api, chain).then(info => {
|
|
110
110
|
observer.next(info);
|
|
@@ -126,6 +126,11 @@ export default class FeeService {
|
|
|
126
126
|
options: undefined
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
+
} else if (type === 'bitcoin') {
|
|
130
|
+
const api = this.state.getBitcoinApi(chain);
|
|
131
|
+
api.api.getRecommendedFeeRate().then(info => {
|
|
132
|
+
observer.next(info);
|
|
133
|
+
}).catch(console.error);
|
|
129
134
|
} else {
|
|
130
135
|
observer.next({
|
|
131
136
|
type,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Brc20BalanceFetchedData, Brc20MetadataFetchedData, InscriptionFetchedData } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types';
|
|
2
|
+
import { BaseApiRequestStrategy } from '@subwallet/extension-base/strategy/api-request-strategy';
|
|
3
|
+
export declare class HiroService extends BaseApiRequestStrategy {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
private constructor();
|
|
6
|
+
private headers;
|
|
7
|
+
isRateLimited(): boolean;
|
|
8
|
+
getUrl(path: string): string;
|
|
9
|
+
getBRC20Metadata(ticker: string): Promise<Brc20MetadataFetchedData>;
|
|
10
|
+
getAddressBRC20BalanceInfo(address: string, params: Record<string, string>): Promise<Brc20BalanceFetchedData>;
|
|
11
|
+
getAddressInscriptionsInfo(params: Record<string, string>): Promise<InscriptionFetchedData>;
|
|
12
|
+
getInscriptionContent(inscriptionId: string): Promise<Record<string, any>>;
|
|
13
|
+
getPreviewUrl(inscriptionId: string): string;
|
|
14
|
+
private static mainnet;
|
|
15
|
+
private static testnet;
|
|
16
|
+
static getInstance(isTestnet?: boolean): HiroService;
|
|
17
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
5
|
+
import { _BTC_SERVICE_TOKEN } from '@subwallet/extension-base/services/chain-service/constants';
|
|
6
|
+
import { BaseApiRequestStrategy } from '@subwallet/extension-base/strategy/api-request-strategy';
|
|
7
|
+
import { BaseApiRequestContext } from '@subwallet/extension-base/strategy/api-request-strategy/context/base';
|
|
8
|
+
import { getRequest } from '@subwallet/extension-base/strategy/api-request-strategy/utils';
|
|
9
|
+
const BITCOIN_API_URL = 'https://btc-api.koni.studio';
|
|
10
|
+
const BITCOIN_API_URL_TEST = 'https://api-testnet.openbit.app';
|
|
11
|
+
export class HiroService extends BaseApiRequestStrategy {
|
|
12
|
+
constructor(url) {
|
|
13
|
+
const context = new BaseApiRequestContext();
|
|
14
|
+
super(context);
|
|
15
|
+
this.baseUrl = url;
|
|
16
|
+
}
|
|
17
|
+
headers = {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
Authorization: `Bearer ${_BTC_SERVICE_TOKEN}`
|
|
20
|
+
};
|
|
21
|
+
isRateLimited() {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
getUrl(path) {
|
|
25
|
+
return `${this.baseUrl}/${path}`;
|
|
26
|
+
}
|
|
27
|
+
getBRC20Metadata(ticker) {
|
|
28
|
+
return this.addRequest(async () => {
|
|
29
|
+
const _rs = await getRequest(this.getUrl(`brc-20/tokens/${ticker}`), undefined, this.headers);
|
|
30
|
+
const rs = await _rs.json();
|
|
31
|
+
if (rs.status_code !== 200) {
|
|
32
|
+
throw new SWError('HiroService.getBRC20Metadata', rs.message);
|
|
33
|
+
}
|
|
34
|
+
return rs.result;
|
|
35
|
+
}, 3);
|
|
36
|
+
}
|
|
37
|
+
getAddressBRC20BalanceInfo(address, params) {
|
|
38
|
+
return this.addRequest(async () => {
|
|
39
|
+
const _rs = await getRequest(this.getUrl(`brc-20/balances/${address}`), params, this.headers);
|
|
40
|
+
const rs = await _rs.json();
|
|
41
|
+
if (rs.status_code !== 200) {
|
|
42
|
+
throw new SWError('HiroService.getAddressBRC20BalanceInfo', rs.message);
|
|
43
|
+
}
|
|
44
|
+
return rs.result;
|
|
45
|
+
}, 3);
|
|
46
|
+
}
|
|
47
|
+
getAddressInscriptionsInfo(params) {
|
|
48
|
+
return this.addRequest(async () => {
|
|
49
|
+
const _rs = await getRequest(this.getUrl('inscriptions'), params, this.headers);
|
|
50
|
+
const rs = await _rs.json();
|
|
51
|
+
if (rs.status_code !== 200) {
|
|
52
|
+
throw new SWError('HiroService.getAddressInscriptionsInfo', rs.message);
|
|
53
|
+
}
|
|
54
|
+
return rs.result;
|
|
55
|
+
}, 0);
|
|
56
|
+
}
|
|
57
|
+
getInscriptionContent(inscriptionId) {
|
|
58
|
+
return this.addRequest(async () => {
|
|
59
|
+
const _rs = await getRequest(this.getUrl(`inscriptions/${inscriptionId}/content`), undefined, this.headers);
|
|
60
|
+
const rs = await _rs.json();
|
|
61
|
+
if (rs.status_code !== 200) {
|
|
62
|
+
throw new SWError('HiroService.getInscriptionContent', rs.message);
|
|
63
|
+
}
|
|
64
|
+
return rs.result;
|
|
65
|
+
}, 0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// todo: handle token authen for url preview
|
|
69
|
+
getPreviewUrl(inscriptionId) {
|
|
70
|
+
return `${BITCOIN_API_URL}/inscriptions/${inscriptionId}/content`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Singleton
|
|
74
|
+
|
|
75
|
+
static getInstance(isTestnet = false) {
|
|
76
|
+
if (isTestnet) {
|
|
77
|
+
if (!HiroService.testnet) {
|
|
78
|
+
HiroService.testnet = new HiroService(BITCOIN_API_URL_TEST);
|
|
79
|
+
}
|
|
80
|
+
return HiroService.testnet;
|
|
81
|
+
} else {
|
|
82
|
+
if (!HiroService.mainnet) {
|
|
83
|
+
HiroService.mainnet = new HiroService(BITCOIN_API_URL);
|
|
84
|
+
}
|
|
85
|
+
return HiroService.mainnet;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Brc20Metadata } from '@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types';
|
|
2
|
+
export declare function getBrc20Metadata(isTestnet: boolean | undefined, ticker: string): Promise<Brc20Metadata>;
|
|
3
|
+
export declare function getInscriptionContent(isTestnet: boolean, inscriptionId: string): Promise<Record<string, any>>;
|
|
4
|
+
export declare function getAddressInscriptions(address: string, isTestnet: boolean, offset?: number, limit?: number): Promise<import("@subwallet/extension-base/services/chain-service/handler/bitcoin/strategy/types").Inscription[]>;
|
|
5
|
+
export declare function getPreviewUrl(inscriptionId: string): string;
|
|
6
|
+
export declare function isValidBrc20Ticker(ticker: string): boolean;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { HiroService } from '@subwallet/extension-base/services/hiro-service';
|
|
5
|
+
|
|
6
|
+
// todo: handle inscription testnet
|
|
7
|
+
export async function getBrc20Metadata(isTestnet = false, ticker) {
|
|
8
|
+
const hiroService = HiroService.getInstance(isTestnet);
|
|
9
|
+
const defaultMetadata = {
|
|
10
|
+
ticker: '',
|
|
11
|
+
decimals: 0
|
|
12
|
+
};
|
|
13
|
+
try {
|
|
14
|
+
const response = await hiroService.getBRC20Metadata(ticker);
|
|
15
|
+
const rs = response === null || response === void 0 ? void 0 : response.token;
|
|
16
|
+
if (rs) {
|
|
17
|
+
return {
|
|
18
|
+
ticker: rs.ticker,
|
|
19
|
+
decimals: rs.decimals
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return defaultMetadata;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.log(`Error on request brc20 metadata with ticker ${ticker}`);
|
|
25
|
+
return defaultMetadata;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function getInscriptionContent(isTestnet, inscriptionId) {
|
|
29
|
+
const hiroService = HiroService.getInstance(isTestnet);
|
|
30
|
+
try {
|
|
31
|
+
return await hiroService.getInscriptionContent(inscriptionId);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.log(`Error on request inscription ${inscriptionId} content`);
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// todo: handle large inscriptions
|
|
39
|
+
export async function getAddressInscriptions(address, isTestnet, offset = 0, limit = 25) {
|
|
40
|
+
const hiroService = HiroService.getInstance(isTestnet);
|
|
41
|
+
try {
|
|
42
|
+
const response = await hiroService.getAddressInscriptionsInfo({
|
|
43
|
+
limit: String(limit),
|
|
44
|
+
offset: String(offset),
|
|
45
|
+
address: String(address)
|
|
46
|
+
});
|
|
47
|
+
return response.results;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.error(`Failed to get ${address} inscriptions with offset ${offset} and limit ${limit}`, error);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function getPreviewUrl(inscriptionId) {
|
|
54
|
+
const hiroService = HiroService.getInstance();
|
|
55
|
+
try {
|
|
56
|
+
return hiroService.getPreviewUrl(inscriptionId);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
console.error(`Failed to get inscription ${inscriptionId} preview url`, error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function isValidBrc20Ticker(ticker) {
|
|
63
|
+
const bytesLength = getByteLength(ticker);
|
|
64
|
+
return bytesLength === 4 || bytesLength === 5;
|
|
65
|
+
}
|
|
66
|
+
function getByteLength(str) {
|
|
67
|
+
const encoder = new TextEncoder();
|
|
68
|
+
const encodedStr = encoder.encode(str);
|
|
69
|
+
|
|
70
|
+
// Return the length of the encoded array, which represents the number of bytes
|
|
71
|
+
return encodedStr.length;
|
|
72
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { TransactionHistoryItem } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
|
+
import { BitcoinTx } from '@subwallet/extension-base/types';
|
|
4
|
+
export declare function parseBitcoinTransferData(address: string, transferItem: BitcoinTx, chainInfo: _ChainInfo): TransactionHistoryItem;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { ChainType, ExtrinsicStatus, ExtrinsicType, TransactionDirection } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
|
+
function isSender(address, transferItem) {
|
|
6
|
+
return transferItem.vin.some(i => i.prevout.scriptpubkey_address === address);
|
|
7
|
+
}
|
|
8
|
+
export function parseBitcoinTransferData(address, transferItem, chainInfo) {
|
|
9
|
+
var _chainInfo$bitcoinInf, _chainInfo$bitcoinInf2, _transferItem$vin$, _transferItem$vin$$pr, _transferItem$vout$;
|
|
10
|
+
const chainType = ChainType.BITCOIN;
|
|
11
|
+
const nativeDecimals = ((_chainInfo$bitcoinInf = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf === void 0 ? void 0 : _chainInfo$bitcoinInf.decimals) || 8;
|
|
12
|
+
const nativeSymbol = ((_chainInfo$bitcoinInf2 = chainInfo.bitcoinInfo) === null || _chainInfo$bitcoinInf2 === void 0 ? void 0 : _chainInfo$bitcoinInf2.symbol) || '';
|
|
13
|
+
const isCurrentAddressSender = isSender(address, transferItem);
|
|
14
|
+
const sender = isCurrentAddressSender ? address : ((_transferItem$vin$ = transferItem.vin[0]) === null || _transferItem$vin$ === void 0 ? void 0 : (_transferItem$vin$$pr = _transferItem$vin$.prevout) === null || _transferItem$vin$$pr === void 0 ? void 0 : _transferItem$vin$$pr.scriptpubkey_address) || '';
|
|
15
|
+
const receiver = isCurrentAddressSender ? ((_transferItem$vout$ = transferItem.vout[0]) === null || _transferItem$vout$ === void 0 ? void 0 : _transferItem$vout$.scriptpubkey_address) || '' : address;
|
|
16
|
+
const amountValue = (() => {
|
|
17
|
+
const targetAddress = isCurrentAddressSender ? receiver : address;
|
|
18
|
+
const vouts = transferItem.vout.filter(i => i.scriptpubkey_address === targetAddress);
|
|
19
|
+
if (vouts.length) {
|
|
20
|
+
return vouts.reduce((total, item) => total + item.value, 0).toString();
|
|
21
|
+
} else {
|
|
22
|
+
return '0';
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
25
|
+
return {
|
|
26
|
+
address,
|
|
27
|
+
origin: 'blockstream',
|
|
28
|
+
time: 0,
|
|
29
|
+
// From api, cannot get time submit transaction
|
|
30
|
+
blockTime: transferItem.status.block_time ? transferItem.status.block_time * 1000 : undefined,
|
|
31
|
+
chainType,
|
|
32
|
+
type: ExtrinsicType.TRANSFER_BALANCE,
|
|
33
|
+
extrinsicHash: transferItem.txid,
|
|
34
|
+
chain: chainInfo.slug,
|
|
35
|
+
direction: address === sender ? TransactionDirection.SEND : TransactionDirection.RECEIVED,
|
|
36
|
+
fee: {
|
|
37
|
+
value: `${transferItem.fee}`,
|
|
38
|
+
decimals: nativeDecimals,
|
|
39
|
+
symbol: nativeSymbol
|
|
40
|
+
},
|
|
41
|
+
from: sender,
|
|
42
|
+
to: receiver,
|
|
43
|
+
blockNumber: transferItem.status.block_height || 0,
|
|
44
|
+
blockHash: transferItem.status.block_hash || '',
|
|
45
|
+
amount: {
|
|
46
|
+
value: amountValue,
|
|
47
|
+
decimals: nativeDecimals,
|
|
48
|
+
symbol: nativeSymbol
|
|
49
|
+
},
|
|
50
|
+
status: transferItem.status.confirmed ? ExtrinsicStatus.SUCCESS : ExtrinsicStatus.PROCESSING
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -6,12 +6,14 @@ export declare enum HistoryRecoverStatus {
|
|
|
6
6
|
API_INACTIVE = "API_INACTIVE",
|
|
7
7
|
LACK_INFO = "LACK_INFO",
|
|
8
8
|
FAIL_DETECT = "FAIL_DETECT",
|
|
9
|
-
UNKNOWN = "UNKNOWN"
|
|
9
|
+
UNKNOWN = "UNKNOWN",
|
|
10
|
+
TX_PENDING = "TX_PENDING"
|
|
10
11
|
}
|
|
11
12
|
export interface TransactionRecoverResult {
|
|
12
13
|
status: HistoryRecoverStatus;
|
|
13
14
|
extrinsicHash?: string;
|
|
14
15
|
blockHash?: string;
|
|
15
16
|
blockNumber?: number;
|
|
17
|
+
blockTime?: number;
|
|
16
18
|
}
|
|
17
19
|
export declare const historyRecover: (history: TransactionHistoryItem, chainService: ChainService) => Promise<TransactionRecoverResult>;
|
|
@@ -11,6 +11,7 @@ export let HistoryRecoverStatus;
|
|
|
11
11
|
HistoryRecoverStatus["LACK_INFO"] = "LACK_INFO";
|
|
12
12
|
HistoryRecoverStatus["FAIL_DETECT"] = "FAIL_DETECT";
|
|
13
13
|
HistoryRecoverStatus["UNKNOWN"] = "UNKNOWN";
|
|
14
|
+
HistoryRecoverStatus["TX_PENDING"] = "TX_PENDING";
|
|
14
15
|
})(HistoryRecoverStatus || (HistoryRecoverStatus = {}));
|
|
15
16
|
const BLOCK_LIMIT = 6;
|
|
16
17
|
const substrateRecover = async (history, chainService) => {
|
|
@@ -204,6 +205,80 @@ const evmRecover = async (history, chainService) => {
|
|
|
204
205
|
};
|
|
205
206
|
}
|
|
206
207
|
};
|
|
208
|
+
const bitcoinRecover = async (history, chainService) => {
|
|
209
|
+
const {
|
|
210
|
+
chain,
|
|
211
|
+
extrinsicHash
|
|
212
|
+
} = history;
|
|
213
|
+
const result = {
|
|
214
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// TODO: 1. Consider rebroadcasting transaction if stuck in mempool
|
|
218
|
+
|
|
219
|
+
try {
|
|
220
|
+
const bitcoinApi = chainService.getBitcoinApi(chain);
|
|
221
|
+
if (bitcoinApi) {
|
|
222
|
+
const api = bitcoinApi.api;
|
|
223
|
+
if (extrinsicHash) {
|
|
224
|
+
try {
|
|
225
|
+
const timeout = new Promise(resolve => {
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
resolve(undefined);
|
|
228
|
+
}, 60000);
|
|
229
|
+
});
|
|
230
|
+
const txStatus = await Promise.race([api.getTransactionStatus(extrinsicHash), timeout]);
|
|
231
|
+
if (!txStatus) {
|
|
232
|
+
return {
|
|
233
|
+
...result,
|
|
234
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (txStatus.confirmed) {
|
|
238
|
+
const transactionDetail = await Promise.race([api.getTransactionDetail(extrinsicHash), timeout]);
|
|
239
|
+
if (transactionDetail) {
|
|
240
|
+
result.blockHash = transactionDetail.status.block_hash || undefined;
|
|
241
|
+
result.blockNumber = transactionDetail.status.block_height || undefined;
|
|
242
|
+
result.blockTime = transactionDetail.status.block_time ? transactionDetail.status.block_time * 1000 : undefined;
|
|
243
|
+
return {
|
|
244
|
+
...result,
|
|
245
|
+
status: HistoryRecoverStatus.SUCCESS
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
...result,
|
|
250
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
251
|
+
};
|
|
252
|
+
} else {
|
|
253
|
+
return {
|
|
254
|
+
...result,
|
|
255
|
+
status: HistoryRecoverStatus.TX_PENDING
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
} catch (e) {
|
|
259
|
+
// Fail when cannot find transaction
|
|
260
|
+
return {
|
|
261
|
+
...result,
|
|
262
|
+
status: HistoryRecoverStatus.FAILED
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
return {
|
|
267
|
+
status: HistoryRecoverStatus.FAIL_DETECT
|
|
268
|
+
};
|
|
269
|
+
} else {
|
|
270
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}: Api not active`);
|
|
271
|
+
return {
|
|
272
|
+
status: HistoryRecoverStatus.API_INACTIVE
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
} catch (e) {
|
|
276
|
+
console.error(`Fail to update history ${chain}-${extrinsicHash}:`, e.message);
|
|
277
|
+
return {
|
|
278
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
};
|
|
207
282
|
|
|
208
283
|
// undefined: Cannot check status
|
|
209
284
|
// true: Transaction success
|
|
@@ -212,12 +287,29 @@ export const historyRecover = async (history, chainService) => {
|
|
|
212
287
|
const {
|
|
213
288
|
chainType
|
|
214
289
|
} = history;
|
|
215
|
-
if (chainType) {
|
|
216
|
-
const checkFunction = chainType === 'substrate' ? substrateRecover : evmRecover;
|
|
217
|
-
return await checkFunction(history, chainService);
|
|
218
|
-
} else {
|
|
290
|
+
if (!chainType) {
|
|
219
291
|
return {
|
|
220
292
|
status: HistoryRecoverStatus.LACK_INFO
|
|
221
293
|
};
|
|
222
294
|
}
|
|
295
|
+
const recoverFunctions = {
|
|
296
|
+
substrate: substrateRecover,
|
|
297
|
+
evm: evmRecover,
|
|
298
|
+
bitcoin: bitcoinRecover
|
|
299
|
+
};
|
|
300
|
+
const checkFunction = recoverFunctions[chainType];
|
|
301
|
+
if (!checkFunction) {
|
|
302
|
+
console.warn(`Chain type ${chainType} is not supported for recoverHistory`);
|
|
303
|
+
return {
|
|
304
|
+
status: HistoryRecoverStatus.UNKNOWN
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
return await checkFunction(history, chainService);
|
|
309
|
+
} catch (error) {
|
|
310
|
+
console.error(`Failed to recover history for chain type ${chainType}:`, error);
|
|
311
|
+
return {
|
|
312
|
+
status: HistoryRecoverStatus.FAILED
|
|
313
|
+
};
|
|
314
|
+
}
|
|
223
315
|
};
|
|
@@ -24,6 +24,7 @@ export declare class HistoryService implements StoppableServiceInterface, Persis
|
|
|
24
24
|
* @todo: Must improve performance of this function
|
|
25
25
|
* */
|
|
26
26
|
private fetchSubscanTransactionHistory;
|
|
27
|
+
private fetchBitcoinTransactionHistory;
|
|
27
28
|
subscribeHistories(chain: string, proxyId: string, cb: (items: TransactionHistoryItem[]) => void): {
|
|
28
29
|
unsubscribe: () => void;
|
|
29
30
|
value: TransactionHistoryItem<ExtrinsicType.TRANSFER_BALANCE>[];
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import { ChainType, ExtrinsicStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
5
|
import { CRON_RECOVER_HISTORY_INTERVAL } from '@subwallet/extension-base/constants';
|
|
6
6
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
7
|
-
import { _isChainEvmCompatible, _isChainSubstrateCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { _isChainBitcoinCompatible, _isChainEvmCompatible, _isChainSubstrateCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { parseBitcoinTransferData } from '@subwallet/extension-base/services/history-service/bitcoin-history';
|
|
8
9
|
import { historyRecover, HistoryRecoverStatus } from '@subwallet/extension-base/services/history-service/helpers/recoverHistoryStatus';
|
|
9
10
|
import { getExtrinsicParserKey } from '@subwallet/extension-base/services/history-service/helpers/subscan-extrinsic-parser-helper';
|
|
10
11
|
import { parseSubscanExtrinsicData, parseSubscanTransferData } from '@subwallet/extension-base/services/history-service/subscan-history';
|
|
@@ -142,20 +143,48 @@ export class HistoryService {
|
|
|
142
143
|
console.log('fetchAllPossibleTransferItems-receive error', e);
|
|
143
144
|
});
|
|
144
145
|
}
|
|
146
|
+
|
|
147
|
+
// Only 1 address is passed in
|
|
148
|
+
async fetchBitcoinTransactionHistory(chain, addresses) {
|
|
149
|
+
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
150
|
+
const chainState = this.chainService.getChainStateByKey(chain);
|
|
151
|
+
if (!chainState.active) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const bitcoinApi = this.chainService.getBitcoinApi(chain);
|
|
155
|
+
const allParsedItems = [];
|
|
156
|
+
for (const address of addresses) {
|
|
157
|
+
const transferItems = await bitcoinApi.api.getAddressTransaction(address);
|
|
158
|
+
const parsedItems = transferItems.map((item, index) => {
|
|
159
|
+
const parsedItem = parseBitcoinTransferData(address, item, chainInfo);
|
|
160
|
+
return {
|
|
161
|
+
...parsedItem,
|
|
162
|
+
apiTxIndex: index
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
allParsedItems.push(...parsedItems);
|
|
166
|
+
}
|
|
167
|
+
await this.addHistoryItems(allParsedItems);
|
|
168
|
+
}
|
|
145
169
|
subscribeHistories(chain, proxyId, cb) {
|
|
146
170
|
const addresses = this.keyringService.context.getDecodedAddresses(proxyId, false);
|
|
171
|
+
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
147
172
|
const evmAddresses = getAddressesByChainType(addresses, [ChainType.EVM]);
|
|
148
173
|
const substrateAddresses = getAddressesByChainType(addresses, [ChainType.SUBSTRATE]);
|
|
174
|
+
const bitcoinAddresses = getAddressesByChainType(addresses, [ChainType.BITCOIN], chainInfo);
|
|
149
175
|
const subscription = this.historySubject.subscribe(items => {
|
|
150
176
|
cb(items.filter(filterHistoryItemByAddressAndChain(chain, addresses)));
|
|
151
177
|
});
|
|
152
|
-
const chainInfo = this.chainService.getChainInfoByKey(chain);
|
|
153
178
|
if (_isChainSubstrateCompatible(chainInfo)) {
|
|
154
179
|
if (_isChainEvmCompatible(chainInfo)) {
|
|
155
180
|
this.fetchSubscanTransactionHistory(chain, evmAddresses);
|
|
156
181
|
} else {
|
|
157
182
|
this.fetchSubscanTransactionHistory(chain, substrateAddresses);
|
|
158
183
|
}
|
|
184
|
+
} else if (_isChainBitcoinCompatible(chainInfo)) {
|
|
185
|
+
this.fetchBitcoinTransactionHistory(chain, bitcoinAddresses).catch(e => {
|
|
186
|
+
console.log('fetchBitcoinTransactionHistory Error', e);
|
|
187
|
+
});
|
|
159
188
|
}
|
|
160
189
|
return {
|
|
161
190
|
unsubscribe: subscription.unsubscribe,
|
|
@@ -195,7 +224,8 @@ export class HistoryService {
|
|
|
195
224
|
if (needUpdateItem) {
|
|
196
225
|
updateRecords.push({
|
|
197
226
|
...needUpdateItem,
|
|
198
|
-
status: item.status
|
|
227
|
+
status: item.status,
|
|
228
|
+
apiTxIndex: item.apiTxIndex
|
|
199
229
|
});
|
|
200
230
|
return;
|
|
201
231
|
}
|
|
@@ -248,6 +278,9 @@ export class HistoryService {
|
|
|
248
278
|
switch (recoverResult.status) {
|
|
249
279
|
case HistoryRecoverStatus.API_INACTIVE:
|
|
250
280
|
break;
|
|
281
|
+
case HistoryRecoverStatus.TX_PENDING:
|
|
282
|
+
delete this.#needRecoveryHistories[currentExtrinsicHash];
|
|
283
|
+
break;
|
|
251
284
|
case HistoryRecoverStatus.FAILED:
|
|
252
285
|
case HistoryRecoverStatus.SUCCESS:
|
|
253
286
|
updateData.status = recoverResult.status === HistoryRecoverStatus.SUCCESS ? ExtrinsicStatus.SUCCESS : ExtrinsicStatus.FAIL;
|
|
@@ -285,7 +318,12 @@ export class HistoryService {
|
|
|
285
318
|
const histories = await this.dbService.getHistories();
|
|
286
319
|
this.#needRecoveryHistories = {};
|
|
287
320
|
histories.filter(history => {
|
|
288
|
-
|
|
321
|
+
if ([ExtrinsicStatus.PROCESSING, ExtrinsicStatus.SUBMITTING].includes(history.status)) {
|
|
322
|
+
return true;
|
|
323
|
+
} else if (history.status === ExtrinsicStatus.SUCCESS && history.chainType === 'bitcoin') {
|
|
324
|
+
return !history.blockTime;
|
|
325
|
+
}
|
|
326
|
+
return false;
|
|
289
327
|
}).filter(history => {
|
|
290
328
|
if (history.type === ExtrinsicType.TRANSFER_XCM) {
|
|
291
329
|
const data = history.additionalInfo;
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
5
5
|
import { CommonAccountErrorType, DeriveErrorType, SWCommonAccountError, SWDeriveError } from '@subwallet/extension-base/types';
|
|
6
6
|
import { createAccountProxyId, derivePair, findSoloNextDerive, findUnifiedNextDerive, getSoloDerivationInfo, parseUnifiedSuriToDerivationPath, validateDerivationPath } from '@subwallet/extension-base/utils';
|
|
7
|
-
import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
7
|
+
import { BitcoinKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
8
8
|
import { keyring } from '@subwallet/ui-keyring';
|
|
9
9
|
import { t } from 'i18next';
|
|
10
10
|
import { assert } from '@polkadot/util';
|
|
11
11
|
import { AccountBaseHandler } from "./Base.js";
|
|
12
|
-
const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton', 'cardano'];
|
|
12
|
+
const validDeriveKeypairTypes = [...SubstrateKeypairTypes, ...EthereumKeypairTypes, 'ton', 'cardano', ...BitcoinKeypairTypes];
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @class AccountDeriveHandler
|
|
@@ -74,7 +74,7 @@ export class AccountMigrationHandler extends AccountBaseHandler {
|
|
|
74
74
|
proxyId
|
|
75
75
|
}).result;
|
|
76
76
|
const newChainTypes = Object.values(AccountChainType).filter(type => !unifiedAccount.chainTypes.includes(type) && SUPPORTED_ACCOUNT_CHAIN_TYPES.includes(type));
|
|
77
|
-
const keypairTypes = newChainTypes.
|
|
77
|
+
const keypairTypes = newChainTypes.flatMap(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
|
|
78
78
|
keypairTypes.forEach(type => {
|
|
79
79
|
const suri = getSuri(mnemonic, type);
|
|
80
80
|
const pair = keyring.createFromUri(suri, {}, type);
|
|
@@ -178,7 +178,7 @@ export class AccountMigrationHandler extends AccountBaseHandler {
|
|
|
178
178
|
password,
|
|
179
179
|
proxyId: firstAccountOldProxyId
|
|
180
180
|
}).result;
|
|
181
|
-
const keypairTypes = SUPPORTED_ACCOUNT_CHAIN_TYPES.
|
|
181
|
+
const keypairTypes = SUPPORTED_ACCOUNT_CHAIN_TYPES.flatMap(chainType => getDefaultKeypairTypeFromAccountChainType(chainType));
|
|
182
182
|
keypairTypes.forEach(type => {
|
|
183
183
|
const suri = getSuri(mnemonic, type);
|
|
184
184
|
const pair = keyring.createFromUri(suri, {}, type);
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { CommonAccountErrorType, SWCommonAccountError } from '@subwallet/extension-base/types';
|
|
5
5
|
import { createAccountProxyId, getSuri } from '@subwallet/extension-base/utils';
|
|
6
6
|
import { tonMnemonicGenerate } from '@subwallet/keyring';
|
|
7
|
+
import { BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes } from '@subwallet/keyring/types';
|
|
7
8
|
import { tonMnemonicValidate } from '@subwallet/keyring/utils';
|
|
8
9
|
import { keyring } from '@subwallet/ui-keyring';
|
|
9
10
|
import { t } from 'i18next';
|
|
@@ -27,7 +28,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
|
|
|
27
28
|
mnemonic: _seed,
|
|
28
29
|
type = 'general'
|
|
29
30
|
}) {
|
|
30
|
-
const types = type === 'general' ? ['sr25519',
|
|
31
|
+
const types = type === 'general' ? ['sr25519', ...EthereumKeypairTypes, 'ton', ...CardanoKeypairTypes, ...BitcoinKeypairTypes] : ['ton-native'];
|
|
31
32
|
const seed = _seed || type === 'general' ? mnemonicGenerate(length) : await tonMnemonicGenerate(length);
|
|
32
33
|
const rs = {
|
|
33
34
|
mnemonic: seed,
|
|
@@ -60,7 +61,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
|
|
|
60
61
|
try {
|
|
61
62
|
assert(mnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
62
63
|
mnemonicTypes = 'general';
|
|
63
|
-
pairTypes = ['sr25519',
|
|
64
|
+
pairTypes = ['sr25519', ...EthereumKeypairTypes, 'ton', ...CardanoKeypairTypes, ...BitcoinKeypairTypes];
|
|
64
65
|
} catch (e) {
|
|
65
66
|
assert(tonMnemonicValidate(phrase), t('Invalid seed phrase. Please try again.'));
|
|
66
67
|
mnemonicTypes = 'ton';
|
|
@@ -97,7 +98,7 @@ export class AccountMnemonicHandler extends AccountBaseHandler {
|
|
|
97
98
|
const addressDict = {};
|
|
98
99
|
let changedAccount = false;
|
|
99
100
|
const hasMasterPassword = keyring.keyring.hasMasterPassword;
|
|
100
|
-
const types = type ? [type] : ['sr25519',
|
|
101
|
+
const types = type ? [type] : ['sr25519', ...EthereumKeypairTypes, 'ton', ...CardanoKeypairTypes, ...BitcoinKeypairTypes];
|
|
101
102
|
if (!hasMasterPassword) {
|
|
102
103
|
if (!password) {
|
|
103
104
|
throw Error(t('The password of each account is needed to set up master password'));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class MigrateNewUnifiedAccount extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
return new Promise(resolve => {
|
|
9
|
+
this.state.settingService.getSettings(currentSettings => {
|
|
10
|
+
this.state.settingService.setSettings({
|
|
11
|
+
...currentSettings,
|
|
12
|
+
isAcknowledgedUnifiedAccountMigration: false
|
|
13
|
+
});
|
|
14
|
+
resolve();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
} catch (e) {
|
|
18
|
+
console.error(e);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -22,6 +22,7 @@ import EnableVaraChain from "./EnableVaraChain.js";
|
|
|
22
22
|
import MigrateAuthUrls from "./MigrateAuthUrls.js";
|
|
23
23
|
import MigrateImportedToken from "./MigrateImportedToken.js";
|
|
24
24
|
import MigrateNetworkSettings from "./MigrateNetworkSettings.js";
|
|
25
|
+
import MigrateNewUnifiedAccount from "./MigrateNewUnifiedAccount.js";
|
|
25
26
|
import MigrateTokenDecimals from "./MigrateTokenDecimals.js";
|
|
26
27
|
import MigrateTransactionHistory from "./MigrateTransactionHistory.js";
|
|
27
28
|
import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.js";
|
|
@@ -61,7 +62,8 @@ export default {
|
|
|
61
62
|
'1.3.6-01': MigrateTransactionHistoryBridge,
|
|
62
63
|
'1.3.10-01': ClearMetadataDatabase,
|
|
63
64
|
'1.3.26-01': DisableZeroBalanceTokens,
|
|
64
|
-
[MYTHOS_MIGRATION_KEY]: ClearMetadataForMythos
|
|
65
|
+
[MYTHOS_MIGRATION_KEY]: ClearMetadataForMythos,
|
|
65
66
|
// [`${EVERYTIME}-1.1.42-02`]: MigrateTransactionHistoryBySymbol
|
|
66
67
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
68
|
+
'1.3.42-01': MigrateNewUnifiedAccount
|
|
67
69
|
};
|