@subwallet/extension-base 1.3.41-0 → 1.3.43-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 +134 -5
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/background/types.d.ts +1 -1
- 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/index.js +16 -1
- package/cjs/core/logic-validation/recipientAddress.js +9 -0
- package/cjs/core/logic-validation/request.js +316 -3
- 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 +477 -93
- package/cjs/koni/background/handlers/State.js +249 -16
- package/cjs/koni/background/handlers/Tabs.js +119 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/bitcoin/index.js +67 -0
- package/cjs/page/index.js +5 -0
- package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
- 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/base/types.js +2 -0
- package/cjs/services/buy-service/index.js +17 -2
- package/cjs/services/chain-service/constants.js +14 -3
- 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/para-chain.js +27 -5
- 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/AuthRequestHandler.js +18 -0
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +427 -0
- package/cjs/services/request-service/index.js +29 -3
- package/cjs/services/rune-service/index.js +105 -0
- package/cjs/services/transaction-service/helpers/index.js +7 -1
- package/cjs/services/transaction-service/index.js +206 -16
- 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/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/auth.js +2 -1
- 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/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/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/core/logic-validation/recipientAddress.js +10 -1
- package/core/logic-validation/request.d.ts +6 -2
- package/core/logic-validation/request.js +309 -3
- 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 +5 -0
- package/koni/background/handlers/Extension.js +387 -9
- package/koni/background/handlers/State.d.ts +10 -3
- package/koni/background/handlers/State.js +240 -15
- package/koni/background/handlers/Tabs.d.ts +7 -2
- package/koni/background/handlers/Tabs.js +119 -9
- package/package.json +149 -8
- package/packageInfo.js +1 -1
- package/page/bitcoin/index.d.ts +17 -0
- package/page/bitcoin/index.js +60 -0
- package/page/index.d.ts +2 -1
- package/page/index.js +4 -0
- 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/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/cardano-transfer.d.ts +2 -0
- package/services/balance-service/transfer/token.js +2 -0
- package/services/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/buy-service/index.js +17 -2
- package/services/chain-service/constants.d.ts +6 -0
- package/services/chain-service/constants.js +8 -2
- 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/para-chain.js +27 -5
- 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/AuthRequestHandler.js +19 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +22 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +414 -0
- package/services/request-service/index.d.ts +8 -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/transaction-service/helpers/index.d.ts +3 -1
- package/services/transaction-service/helpers/index.js +5 -0
- package/services/transaction-service/index.d.ts +4 -5
- package/services/transaction-service/index.js +205 -17
- package/services/transaction-service/types.d.ts +13 -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 +19 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/buy.d.ts +1 -1
- 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/auth.js +3 -2
- 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/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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { SWError } from '@subwallet/extension-base/background/errors/SWError';
|
|
5
|
+
export class BaseApiRequestStrategy {
|
|
6
|
+
nextId = 0;
|
|
7
|
+
isRunning = false;
|
|
8
|
+
requestMap = {};
|
|
9
|
+
processInterval = undefined;
|
|
10
|
+
getId() {
|
|
11
|
+
return this.nextId++;
|
|
12
|
+
}
|
|
13
|
+
constructor(context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
}
|
|
16
|
+
addRequest(run, ordinal) {
|
|
17
|
+
const newId = this.getId();
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
this.requestMap[newId] = {
|
|
20
|
+
id: newId,
|
|
21
|
+
status: 'pending',
|
|
22
|
+
retry: -1,
|
|
23
|
+
ordinal,
|
|
24
|
+
run,
|
|
25
|
+
resolve,
|
|
26
|
+
reject
|
|
27
|
+
};
|
|
28
|
+
if (!this.isRunning) {
|
|
29
|
+
this.process();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
process() {
|
|
34
|
+
this.stop();
|
|
35
|
+
this.isRunning = true;
|
|
36
|
+
const maxRetry = this.context.maxRetry;
|
|
37
|
+
const interval = setInterval(() => {
|
|
38
|
+
const remainingRequests = Object.values(this.requestMap);
|
|
39
|
+
if (remainingRequests.length === 0) {
|
|
40
|
+
this.isRunning = false;
|
|
41
|
+
clearInterval(interval);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get first this.limit requests base on id
|
|
46
|
+
const requests = remainingRequests.filter(request => request.status !== 'running').sort((a, b) => a.id - b.id).sort((a, b) => a.ordinal - b.ordinal).slice(0, this.context.callRate);
|
|
47
|
+
|
|
48
|
+
// Start requests
|
|
49
|
+
requests.forEach(request => {
|
|
50
|
+
request.status = 'running';
|
|
51
|
+
request.run().then(rs => {
|
|
52
|
+
request.resolve(rs);
|
|
53
|
+
}).catch(e => {
|
|
54
|
+
const isRateLimited = this.isRateLimited(e);
|
|
55
|
+
|
|
56
|
+
// Limit rate
|
|
57
|
+
if (isRateLimited) {
|
|
58
|
+
if (request.retry < maxRetry) {
|
|
59
|
+
request.status = 'pending';
|
|
60
|
+
request.retry++;
|
|
61
|
+
this.context.reduceLimitRate();
|
|
62
|
+
} else {
|
|
63
|
+
// Reject request
|
|
64
|
+
request.reject(new SWError('MAX_RETRY', String(e)));
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
request.reject(new SWError('UNKNOWN', String(e)));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}, this.context.intervalCheck);
|
|
72
|
+
this.processInterval = interval;
|
|
73
|
+
}
|
|
74
|
+
stop() {
|
|
75
|
+
clearInterval(this.processInterval);
|
|
76
|
+
this.processInterval = undefined;
|
|
77
|
+
}
|
|
78
|
+
setContext(context) {
|
|
79
|
+
this.stop();
|
|
80
|
+
this.context = context;
|
|
81
|
+
this.process();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ApiRequestContext {
|
|
2
|
+
callRate: number;
|
|
3
|
+
limitRate: number;
|
|
4
|
+
intervalCheck: number;
|
|
5
|
+
maxRetry: number;
|
|
6
|
+
reduceLimitRate: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface ApiRequestStrategy {
|
|
9
|
+
addRequest: <T>(run: ApiRequest<T>['run'], ordinal: number) => Promise<T>;
|
|
10
|
+
setContext: (context: ApiRequestContext) => void;
|
|
11
|
+
stop: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface ApiRequest<T> {
|
|
14
|
+
id: number;
|
|
15
|
+
retry: number;
|
|
16
|
+
/** Serve smaller first */
|
|
17
|
+
ordinal: number;
|
|
18
|
+
status: 'pending' | 'running';
|
|
19
|
+
run: () => Promise<any>;
|
|
20
|
+
resolve: (value: any) => T;
|
|
21
|
+
reject: (error?: any) => void;
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import fetch from 'cross-fetch';
|
|
5
|
+
export const postRequest = (url, body, headers, jsonBody = true) => {
|
|
6
|
+
return fetch(url, {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: headers || {
|
|
9
|
+
'Content-Type': 'application/json'
|
|
10
|
+
},
|
|
11
|
+
body: jsonBody ? JSON.stringify(body) : body
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export const getRequest = (url, params, headers) => {
|
|
15
|
+
const queryString = params ? Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&') : '';
|
|
16
|
+
const _url = `${url}?${queryString}`;
|
|
17
|
+
return fetch(_url, {
|
|
18
|
+
method: 'GET',
|
|
19
|
+
headers: headers || {
|
|
20
|
+
'Content-Type': 'application/json'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
@@ -116,7 +116,7 @@ export declare enum AccountChainType {
|
|
|
116
116
|
CARDANO = "cardano"
|
|
117
117
|
}
|
|
118
118
|
export declare const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP: Record<string, number>;
|
|
119
|
-
export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES:
|
|
119
|
+
export declare const SUPPORTED_ACCOUNT_CHAIN_TYPES: AccountChainType[];
|
|
120
120
|
export declare enum AccountActions {
|
|
121
121
|
DERIVE = "DERIVE",
|
|
122
122
|
EXPORT_MNEMONIC = "EXPORT_MNEMONIC",
|
|
@@ -74,7 +74,7 @@ export const ACCOUNT_CHAIN_TYPE_ORDINAL_MAP = {
|
|
|
74
74
|
[AccountChainType.CARDANO]: 4,
|
|
75
75
|
[AccountChainType.BITCOIN]: 5
|
|
76
76
|
};
|
|
77
|
-
export const SUPPORTED_ACCOUNT_CHAIN_TYPES = [
|
|
77
|
+
export const SUPPORTED_ACCOUNT_CHAIN_TYPES = [AccountChainType.SUBSTRATE, AccountChainType.ETHEREUM, AccountChainType.TON, AccountChainType.CARDANO, AccountChainType.BITCOIN];
|
|
78
78
|
export let AccountActions;
|
|
79
79
|
|
|
80
80
|
/**
|
package/types/balance/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
3
3
|
import { _BalanceMetadata, APIItemState, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
-
import { _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
4
|
+
import { _BitcoinApi, _CardanoApi, _EvmApi, _SubstrateApi, _TonApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
5
|
import { BN } from '@polkadot/util';
|
|
6
6
|
export interface TokenBalanceRaw {
|
|
7
7
|
reserved: BN;
|
|
@@ -55,3 +55,6 @@ export interface SubscribeTonPalletBalance extends SubscribeBasePalletBalance {
|
|
|
55
55
|
export interface SusbcribeCardanoPalletBalance extends SubscribeBasePalletBalance {
|
|
56
56
|
cardanoApi: _CardanoApi;
|
|
57
57
|
}
|
|
58
|
+
export interface SusbcribeBitcoinPalletBalance extends SubscribeBasePalletBalance {
|
|
59
|
+
bitcoinApi: _BitcoinApi;
|
|
60
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { PsbtTransactionArg } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
2
|
import { BaseRequestSign } from '@subwallet/extension-base/types';
|
|
2
3
|
import { FeeChainType, FeeDetail, TransactionFee } from '../fee';
|
|
3
4
|
export interface RequestSubscribeTransfer extends TransactionFee {
|
|
4
5
|
address: string;
|
|
6
|
+
to?: string;
|
|
5
7
|
chain: string;
|
|
6
8
|
value: string;
|
|
7
9
|
token: string;
|
|
@@ -15,6 +17,12 @@ export interface ResponseSubscribeTransfer {
|
|
|
15
17
|
feePercentageSpecialCase?: number;
|
|
16
18
|
error?: string;
|
|
17
19
|
}
|
|
20
|
+
export interface RequestSubmitTransferWithId extends RequestSubmitTransfer {
|
|
21
|
+
id?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ResponseSubscribeTransferConfirmation extends Omit<ResponseSubscribeTransfer, 'maxTransferable'> {
|
|
24
|
+
error?: string;
|
|
25
|
+
}
|
|
18
26
|
export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
19
27
|
chain: string;
|
|
20
28
|
from: string;
|
|
@@ -24,3 +32,14 @@ export interface RequestSubmitTransfer extends BaseRequestSign, TransactionFee {
|
|
|
24
32
|
value: string;
|
|
25
33
|
transferBounceable?: boolean;
|
|
26
34
|
}
|
|
35
|
+
export interface RequestSubmitSignPsbtTransfer extends BaseRequestSign {
|
|
36
|
+
id: string;
|
|
37
|
+
chain: string;
|
|
38
|
+
from: string;
|
|
39
|
+
to: string;
|
|
40
|
+
value: string;
|
|
41
|
+
txInput: PsbtTransactionArg[];
|
|
42
|
+
txOutput: PsbtTransactionArg[];
|
|
43
|
+
tokenSlug: string;
|
|
44
|
+
psbt: string;
|
|
45
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export interface UtxoResponseItem {
|
|
2
|
+
txid: string;
|
|
3
|
+
vout: number;
|
|
4
|
+
status: {
|
|
5
|
+
confirmed: boolean;
|
|
6
|
+
block_height?: number;
|
|
7
|
+
block_hash?: string;
|
|
8
|
+
block_time?: number;
|
|
9
|
+
};
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
export interface DetermineUtxosForSpendArgs {
|
|
13
|
+
sender: string;
|
|
14
|
+
amount: number;
|
|
15
|
+
feeRate: number;
|
|
16
|
+
recipient: string;
|
|
17
|
+
utxos: UtxoResponseItem[];
|
|
18
|
+
}
|
|
19
|
+
interface DetermineUtxosOutput {
|
|
20
|
+
value: number;
|
|
21
|
+
address?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DetermineUtxosForSpendResult {
|
|
24
|
+
filteredUtxos: UtxoResponseItem[];
|
|
25
|
+
inputs: UtxoResponseItem[];
|
|
26
|
+
outputs: DetermineUtxosOutput[];
|
|
27
|
+
size: number;
|
|
28
|
+
fee: number;
|
|
29
|
+
}
|
|
30
|
+
export declare class InsufficientFundsError extends Error {
|
|
31
|
+
constructor();
|
|
32
|
+
}
|
|
33
|
+
interface BitcoinTransactionIssuance {
|
|
34
|
+
asset_id: string;
|
|
35
|
+
is_reissuance: boolean;
|
|
36
|
+
asset_blinding_nonce: number;
|
|
37
|
+
asset_entropy: number;
|
|
38
|
+
contract_hash: string;
|
|
39
|
+
assetamount?: number;
|
|
40
|
+
assetamountcommitment?: number;
|
|
41
|
+
tokenamount?: number;
|
|
42
|
+
tokenamountcommitment?: number;
|
|
43
|
+
}
|
|
44
|
+
interface BitcoinTransactionPegOut {
|
|
45
|
+
genesis_hash: string;
|
|
46
|
+
scriptpubkey: string;
|
|
47
|
+
scriptpubkey_asm: string;
|
|
48
|
+
scriptpubkey_address: string;
|
|
49
|
+
}
|
|
50
|
+
export interface BitcoinTransactionStatus {
|
|
51
|
+
confirmed: boolean;
|
|
52
|
+
block_height?: number | null;
|
|
53
|
+
block_hash?: string | null;
|
|
54
|
+
block_time?: number | null;
|
|
55
|
+
}
|
|
56
|
+
export interface BitcoinTransactionVectorOutput {
|
|
57
|
+
scriptpubkey: string;
|
|
58
|
+
scriptpubkey_asm: string;
|
|
59
|
+
scriptpubkey_type: string;
|
|
60
|
+
scriptpubkey_address: string;
|
|
61
|
+
value: number;
|
|
62
|
+
valuecommitment?: number;
|
|
63
|
+
asset?: string;
|
|
64
|
+
assetcommitment?: number;
|
|
65
|
+
pegout?: BitcoinTransactionPegOut | null;
|
|
66
|
+
}
|
|
67
|
+
export interface BitcoinTransactionVectorInput {
|
|
68
|
+
inner_redeemscript_asm?: string;
|
|
69
|
+
inner_witnessscript_asm?: string;
|
|
70
|
+
is_coinbase: boolean;
|
|
71
|
+
is_pegin?: boolean;
|
|
72
|
+
issuance?: BitcoinTransactionIssuance | null;
|
|
73
|
+
prevout: BitcoinTransactionVectorOutput;
|
|
74
|
+
scriptsig: string;
|
|
75
|
+
scriptsig_asm: string;
|
|
76
|
+
sequence: number;
|
|
77
|
+
txid: string;
|
|
78
|
+
vout: number;
|
|
79
|
+
witness: string[];
|
|
80
|
+
}
|
|
81
|
+
export interface BitcoinTx {
|
|
82
|
+
fee: number;
|
|
83
|
+
locktime: number;
|
|
84
|
+
size: number;
|
|
85
|
+
status: BitcoinTransactionStatus;
|
|
86
|
+
tx_type?: string;
|
|
87
|
+
txid: string;
|
|
88
|
+
version: number;
|
|
89
|
+
vin: BitcoinTransactionVectorInput[];
|
|
90
|
+
vout: BitcoinTransactionVectorOutput[];
|
|
91
|
+
weight: number;
|
|
92
|
+
}
|
|
93
|
+
export {};
|
package/types/bitcoin.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// https://github.com/leather-wallet/extension/blob/dev/src/app/query/bitcoin/bitcoin-client.ts
|
|
5
|
+
|
|
6
|
+
// https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts
|
|
7
|
+
|
|
8
|
+
// https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/coinselect/local-coin-selection.ts
|
|
9
|
+
export class InsufficientFundsError extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super('Insufficient funds');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
// Source: https://github.com/Blockstream/esplora/blob/master/API.md#transaction-format
|
|
15
|
+
// ---------------
|
|
16
|
+
|
|
17
|
+
// ---------------
|
package/types/buy.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export interface BuyService {
|
|
|
4
4
|
symbol: string;
|
|
5
5
|
}
|
|
6
6
|
export declare type SupportService = 'transak' | 'banxa' | 'coinbase' | 'moonpay' | 'onramper' | 'meld';
|
|
7
|
-
export declare type OnrampAccountSupportType = 'ETHEREUM' | 'SUBSTRATE';
|
|
7
|
+
export declare type OnrampAccountSupportType = 'ETHEREUM' | 'SUBSTRATE' | 'TON' | 'CARDANO';
|
|
8
8
|
export interface BuyTokenInfo {
|
|
9
9
|
network: string;
|
|
10
10
|
symbol: string;
|
package/types/fee/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type FeeChainType = 'evm' | 'substrate' | 'ton' | 'cardano';
|
|
1
|
+
export declare type FeeChainType = 'evm' | 'substrate' | 'ton' | 'cardano' | 'bitcoin';
|
|
2
2
|
export interface BaseFeeInfo {
|
|
3
3
|
busyNetwork: boolean;
|
|
4
4
|
type: FeeChainType;
|
|
@@ -6,3 +6,6 @@ export interface BaseFeeInfo {
|
|
|
6
6
|
export interface BaseFeeDetail {
|
|
7
7
|
estimatedFee: string;
|
|
8
8
|
}
|
|
9
|
+
export interface BaseFeeTime {
|
|
10
|
+
time: number;
|
|
11
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BaseFeeDetail, BaseFeeInfo, BaseFeeTime } from './base';
|
|
2
|
+
import { FeeDefaultOption } from './option';
|
|
3
|
+
export interface BitcoinFeeRate {
|
|
4
|
+
feeRate: number;
|
|
5
|
+
}
|
|
6
|
+
export declare type BitcoinFeeRateDetail = BitcoinFeeRate & BaseFeeTime;
|
|
7
|
+
export interface BitcoinFeeInfo extends BaseFeeInfo {
|
|
8
|
+
type: 'bitcoin';
|
|
9
|
+
options: {
|
|
10
|
+
slow: BitcoinFeeRateDetail;
|
|
11
|
+
average: BitcoinFeeRateDetail;
|
|
12
|
+
fast: BitcoinFeeRateDetail;
|
|
13
|
+
default: FeeDefaultOption;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface BitcoinFeeDetail extends BitcoinFeeInfo, BaseFeeDetail {
|
|
17
|
+
vSize: number;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/types/fee/index.d.ts
CHANGED
package/types/fee/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { BitcoinFeeDetail, BitcoinFeeInfo, BitcoinFeeRate } from '@subwallet/extension-base/types';
|
|
1
2
|
import { BehaviorSubject } from 'rxjs';
|
|
2
3
|
import { CardanoFeeDetail, CardanoFeeInfo, CardanoTipInfo } from './cardano';
|
|
3
4
|
import { EvmEIP1559FeeOption, EvmFeeDetail, EvmFeeInfo } from './evm';
|
|
4
5
|
import { SubstrateFeeDetail, SubstrateFeeInfo, SubstrateTipInfo } from './substrate';
|
|
5
6
|
import { TonFeeDetail, TonFeeInfo, TonTipInfo } from './ton';
|
|
6
|
-
export declare type FeeInfo = EvmFeeInfo | SubstrateFeeInfo | TonFeeInfo | CardanoFeeInfo;
|
|
7
|
-
export declare type FeeDetail = EvmFeeDetail | SubstrateFeeDetail | TonFeeDetail | CardanoFeeDetail;
|
|
8
|
-
export declare type FeeCustom = EvmEIP1559FeeOption | SubstrateTipInfo | TonTipInfo | CardanoTipInfo;
|
|
7
|
+
export declare type FeeInfo = EvmFeeInfo | SubstrateFeeInfo | TonFeeInfo | CardanoFeeInfo | BitcoinFeeInfo;
|
|
8
|
+
export declare type FeeDetail = EvmFeeDetail | SubstrateFeeDetail | TonFeeDetail | CardanoFeeDetail | BitcoinFeeDetail;
|
|
9
|
+
export declare type FeeCustom = EvmEIP1559FeeOption | SubstrateTipInfo | TonTipInfo | CardanoTipInfo | BitcoinFeeRate;
|
|
9
10
|
export interface FeeSubscription {
|
|
10
11
|
observer: BehaviorSubject<FeeInfo | undefined>;
|
|
11
12
|
subscription: Record<string, VoidFunction>;
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
package/utils/account/analyze.js
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { resolveAzeroAddressToDomain, resolveAzeroDomainToAddress } from '@subwallet/extension-base/koni/api/dotsama/domain';
|
|
5
|
-
import {
|
|
5
|
+
import { _getChainSubstrateAddressPrefix, _isChainInfoCompatibleWithAccountInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
6
|
import { AccountChainType, AnalyzedGroup } from '@subwallet/extension-base/types';
|
|
7
|
+
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
7
8
|
import { isAddress } from '@polkadot/util-crypto';
|
|
8
9
|
import { _reformatAddressWithChain, reformatAddress } from "./common.js";
|
|
9
10
|
// TODO: Re-confirm to compare without
|
|
@@ -51,14 +52,13 @@ export const _analyzeAddress = async (data, accountProxies, contacts, chainInfo,
|
|
|
51
52
|
const chain = chainInfo.slug;
|
|
52
53
|
const _data = data.trim().toLowerCase();
|
|
53
54
|
const options = [];
|
|
54
|
-
const currentChainType = _chainInfoToChainType(chainInfo);
|
|
55
55
|
let current;
|
|
56
56
|
|
|
57
57
|
// Filter account proxies
|
|
58
58
|
for (const accountProxy of accountProxies) {
|
|
59
59
|
const _name = accountProxy.name.trim().toLowerCase();
|
|
60
60
|
const nameCondition = isNameValid(_data, _name);
|
|
61
|
-
const filterAccounts = accountProxy.accounts.filter(account => account.chainType
|
|
61
|
+
const filterAccounts = accountProxy.accounts.filter(account => _isChainInfoCompatibleWithAccountInfo(chainInfo, account.chainType, account.type));
|
|
62
62
|
for (const account of filterAccounts) {
|
|
63
63
|
const addressCondition = isStrValidWithAddress(_data, account, chainInfo);
|
|
64
64
|
const condition = nameCondition !== 'invalid' ? nameCondition : addressCondition;
|
|
@@ -86,7 +86,7 @@ export const _analyzeAddress = async (data, accountProxies, contacts, chainInfo,
|
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
-
const filterContacts = contacts.filter(contact => contact.chainType
|
|
89
|
+
const filterContacts = contacts.filter(contact => _isChainInfoCompatibleWithAccountInfo(chainInfo, contact.chainType, getKeypairTypeByAddress(contact.address)));
|
|
90
90
|
|
|
91
91
|
// Filter address book addresses
|
|
92
92
|
for (const contact of filterContacts) {
|
|
@@ -6,15 +6,14 @@ export declare function isAccountAll(address?: string): boolean;
|
|
|
6
6
|
export declare function reformatAddress(address: string, networkPrefix?: number, isEthereum?: boolean): string;
|
|
7
7
|
export declare const _reformatAddressWithChain: (address: string, chainInfo: _ChainInfo) => string;
|
|
8
8
|
export declare const getAccountChainTypeForAddress: (address: string) => AccountChainType;
|
|
9
|
-
|
|
10
|
-
[ChainType
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
[ChainType.CARDANO]: string[];
|
|
9
|
+
declare type AddressesByChainType = {
|
|
10
|
+
[key in ChainType]: string[];
|
|
11
|
+
};
|
|
12
|
+
interface ExtendAddressesByChainType extends AddressesByChainType {
|
|
13
|
+
_bitcoin: string[];
|
|
15
14
|
}
|
|
16
|
-
export declare function getAddressesByChainType(addresses: string[], chainTypes: ChainType[]): string[];
|
|
17
|
-
export declare function getAddressesByChainTypeMap(addresses: string[]):
|
|
15
|
+
export declare function getAddressesByChainType(addresses: string[], chainTypes: ChainType[], chainInfo?: _ChainInfo): string[];
|
|
16
|
+
export declare function getAddressesByChainTypeMap(addresses: string[], chainInfo?: _ChainInfo): ExtendAddressesByChainType;
|
|
18
17
|
export declare function quickFormatAddressToCompare(address?: string): string | undefined;
|
|
19
18
|
/** @deprecated */
|
|
20
19
|
export declare const modifyAccountName: (type: KeypairType, name: string, modify: boolean) => string;
|
package/utils/account/common.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { ChainType } from '@subwallet/extension-base/background/KoniTypes';
|
|
5
4
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
6
5
|
import { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
6
|
import { AccountChainType } from '@subwallet/extension-base/types';
|
|
8
7
|
import { getAccountChainTypeFromKeypairType } from '@subwallet/extension-base/utils';
|
|
9
8
|
import { decodeAddress, encodeAddress, getKeypairTypeByAddress, isAddress, isBitcoinAddress, isCardanoAddress, isTonAddress } from '@subwallet/keyring';
|
|
9
|
+
import { getBitcoinAddressInfo } from '@subwallet/keyring/utils/address/validate';
|
|
10
10
|
import { ethereumEncode, isEthereumAddress } from '@polkadot/util-crypto';
|
|
11
11
|
export function isAccountAll(address) {
|
|
12
12
|
return address === ALL_ACCOUNT_KEY;
|
|
@@ -52,20 +52,22 @@ export const getAccountChainTypeForAddress = address => {
|
|
|
52
52
|
const type = getKeypairTypeByAddress(address);
|
|
53
53
|
return getAccountChainTypeFromKeypairType(type);
|
|
54
54
|
};
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
// TODO: Recheck the usage of this function for Bitcoin; it is currently applied to history.
|
|
56
|
+
export function getAddressesByChainType(addresses, chainTypes, chainInfo) {
|
|
57
|
+
const addressByChainTypeMap = getAddressesByChainTypeMap(addresses, chainInfo);
|
|
57
58
|
return chainTypes.map(chainType => {
|
|
58
59
|
return addressByChainTypeMap[chainType];
|
|
59
60
|
}).flat(); // todo: recheck
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
export function getAddressesByChainTypeMap(addresses) {
|
|
63
|
+
export function getAddressesByChainTypeMap(addresses, chainInfo) {
|
|
63
64
|
const addressByChainType = {
|
|
64
65
|
substrate: [],
|
|
65
66
|
evm: [],
|
|
66
67
|
bitcoin: [],
|
|
67
68
|
ton: [],
|
|
68
|
-
cardano: []
|
|
69
|
+
cardano: [],
|
|
70
|
+
_bitcoin: []
|
|
69
71
|
};
|
|
70
72
|
addresses.forEach(address => {
|
|
71
73
|
if (isEthereumAddress(address)) {
|
|
@@ -73,7 +75,15 @@ export function getAddressesByChainTypeMap(addresses) {
|
|
|
73
75
|
} else if (isTonAddress(address)) {
|
|
74
76
|
addressByChainType.ton.push(address);
|
|
75
77
|
} else if (isBitcoinAddress(address)) {
|
|
76
|
-
|
|
78
|
+
const addressInfo = getBitcoinAddressInfo(address);
|
|
79
|
+
if (chainInfo !== null && chainInfo !== void 0 && chainInfo.bitcoinInfo) {
|
|
80
|
+
const isNetworkMatch = addressInfo.network === chainInfo.bitcoinInfo.bitcoinNetwork;
|
|
81
|
+
if (isNetworkMatch) {
|
|
82
|
+
addressByChainType.bitcoin.push(address);
|
|
83
|
+
} else {
|
|
84
|
+
addressByChainType._bitcoin.push(address);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
77
87
|
} else if (isCardanoAddress(address)) {
|
|
78
88
|
addressByChainType.cardano.push(address);
|
|
79
89
|
} else {
|