@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
|
@@ -2,32 +2,55 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { getDerivePath } from '@subwallet/keyring';
|
|
5
|
-
import { EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
5
|
+
import { BitcoinKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes } from '@subwallet/keyring/types';
|
|
6
6
|
import { keyring } from '@subwallet/ui-keyring';
|
|
7
7
|
import { t } from 'i18next';
|
|
8
8
|
import { assert } from '@polkadot/util';
|
|
9
|
-
import { validateCardanoDerivationPath, validateEvmDerivationPath, validateOtherSubstrateDerivationPath, validateSr25519DerivationPath, validateTonDerivationPath, validateUnifiedDerivationPath } from "../validate.js";
|
|
9
|
+
import { validateBitcoinDerivationPath, validateCardanoDerivationPath, validateEvmDerivationPath, validateOtherSubstrateDerivationPath, validateSr25519DerivationPath, validateTonDerivationPath, validateUnifiedDerivationPath } from "../validate.js";
|
|
10
|
+
const bitPathLv1 = "m/{proposal}'/{slip44}'/{firstIndex}'/0/0";
|
|
11
|
+
const bitPathLv2 = "m/{proposal}'/{slip44}'/{firstIndex}'/0/0/{secondIndex}";
|
|
12
|
+
const getBitLv1DerivePathFunction = (slip44, proposal) => {
|
|
13
|
+
return bitPathLv1.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
|
|
14
|
+
};
|
|
15
|
+
const getBitLv2DerivePathFunction = (slip44, proposal) => {
|
|
16
|
+
return bitPathLv2.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
|
|
17
|
+
};
|
|
18
|
+
const level1DerivationPathMap = {
|
|
19
|
+
ethereum: "m/44'/60'/0'/0/{firstIndex}",
|
|
20
|
+
ton: "m/44'/607'/{firstIndex}'",
|
|
21
|
+
cardano: "m/1852'/1815'/{firstIndex}'",
|
|
22
|
+
'bitcoin-44': getBitLv1DerivePathFunction(0, 44),
|
|
23
|
+
'bitcoin-84': getBitLv1DerivePathFunction(0, 84),
|
|
24
|
+
'bitcoin-86': getBitLv1DerivePathFunction(0, 86),
|
|
25
|
+
'bittest-44': getBitLv1DerivePathFunction(1, 44),
|
|
26
|
+
'bittest-84': getBitLv1DerivePathFunction(1, 84),
|
|
27
|
+
'bittest-86': getBitLv1DerivePathFunction(1, 86)
|
|
28
|
+
};
|
|
29
|
+
const level2DerivationPathMap = {
|
|
30
|
+
ethereum: "m/44'/60'/0'/0/{firstIndex}/{secondIndex}",
|
|
31
|
+
ton: "m/44'/607'/{firstIndex}'/{secondIndex}'",
|
|
32
|
+
cardano: "m/1852'/1815'/{firstIndex}'/{secondIndex}'",
|
|
33
|
+
'bitcoin-44': getBitLv2DerivePathFunction(0, 44),
|
|
34
|
+
'bitcoin-84': getBitLv2DerivePathFunction(0, 84),
|
|
35
|
+
'bitcoin-86': getBitLv2DerivePathFunction(0, 86),
|
|
36
|
+
'bittest-44': getBitLv2DerivePathFunction(1, 44),
|
|
37
|
+
'bittest-84': getBitLv2DerivePathFunction(1, 84),
|
|
38
|
+
'bittest-86': getBitLv2DerivePathFunction(1, 86)
|
|
39
|
+
};
|
|
10
40
|
export const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
11
41
|
const reg = /^\/\/(\d+)(\/\/\d+)?$/;
|
|
12
42
|
if (suri.match(reg)) {
|
|
13
43
|
const [, firstIndex, secondData] = suri.match(reg);
|
|
14
|
-
const first = parseInt(firstIndex, 10);
|
|
15
44
|
if (secondData) {
|
|
16
45
|
const [, secondIndex] = secondData.match(/\/\/(\d+)/);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return `m/44'/607'/${first}'/${secondIndex}'`;
|
|
21
|
-
} else if (type === 'cardano') {
|
|
22
|
-
return `m/1852'/1815'/${first}'/${secondIndex}'`;
|
|
46
|
+
const path = level2DerivationPathMap[type];
|
|
47
|
+
if (path) {
|
|
48
|
+
return path.replace('{firstIndex}', firstIndex).replace('{secondIndex}', secondIndex);
|
|
23
49
|
}
|
|
24
50
|
} else {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return `m/44'/607'/${first}'`;
|
|
29
|
-
} else if (type === 'cardano') {
|
|
30
|
-
return `m/1852'/1815'/${first}'`;
|
|
51
|
+
const path = level1DerivationPathMap[type];
|
|
52
|
+
if (path) {
|
|
53
|
+
return path.replace('{firstIndex}', firstIndex);
|
|
31
54
|
}
|
|
32
55
|
}
|
|
33
56
|
if (SubstrateKeypairTypes.includes(type)) {
|
|
@@ -36,6 +59,33 @@ export const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
|
36
59
|
}
|
|
37
60
|
return '';
|
|
38
61
|
};
|
|
62
|
+
const validateNonSubstrateDerivationPath = (derivePath, type) => {
|
|
63
|
+
let validateTypeRs;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case 'ethereum':
|
|
66
|
+
validateTypeRs = validateEvmDerivationPath(derivePath);
|
|
67
|
+
break;
|
|
68
|
+
case 'ton':
|
|
69
|
+
validateTypeRs = validateTonDerivationPath(derivePath);
|
|
70
|
+
break;
|
|
71
|
+
case 'cardano':
|
|
72
|
+
validateTypeRs = validateCardanoDerivationPath(derivePath);
|
|
73
|
+
break;
|
|
74
|
+
case 'bitcoin-44':
|
|
75
|
+
case 'bitcoin-84':
|
|
76
|
+
case 'bitcoin-86':
|
|
77
|
+
case 'bittest-44':
|
|
78
|
+
case 'bittest-84':
|
|
79
|
+
case 'bittest-86':
|
|
80
|
+
validateTypeRs = validateBitcoinDerivationPath(derivePath);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (validateTypeRs && validateTypeRs.type === type) {
|
|
84
|
+
return validateTypeRs;
|
|
85
|
+
} else {
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
39
89
|
export const getSoloDerivationInfo = (type, metadata = {}) => {
|
|
40
90
|
const {
|
|
41
91
|
derivationPath: derivePath,
|
|
@@ -44,8 +94,7 @@ export const getSoloDerivationInfo = (type, metadata = {}) => {
|
|
|
44
94
|
} = metadata;
|
|
45
95
|
if (suri) {
|
|
46
96
|
if (derivePath) {
|
|
47
|
-
const
|
|
48
|
-
const validateTypeRs = validateTypeFunc(derivePath);
|
|
97
|
+
const validateTypeRs = validateNonSubstrateDerivationPath(derivePath, type);
|
|
49
98
|
if (validateTypeRs) {
|
|
50
99
|
return {
|
|
51
100
|
suri: validateTypeRs.suri,
|
|
@@ -101,8 +150,7 @@ export const getSoloDerivationInfo = (type, metadata = {}) => {
|
|
|
101
150
|
}
|
|
102
151
|
} else {
|
|
103
152
|
if (derivePath) {
|
|
104
|
-
const
|
|
105
|
-
const validateTypeRs = validateTypeFunc(derivePath);
|
|
153
|
+
const validateTypeRs = validateNonSubstrateDerivationPath(derivePath, type);
|
|
106
154
|
if (validateTypeRs) {
|
|
107
155
|
return {
|
|
108
156
|
suri: validateTypeRs.suri,
|
|
@@ -215,6 +263,7 @@ export const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
215
263
|
const isEvm = EthereumKeypairTypes.includes(parentPair.type);
|
|
216
264
|
const isTon = parentPair.type === 'ton';
|
|
217
265
|
const isCardano = parentPair.type === 'cardano';
|
|
266
|
+
const isBitcoin = BitcoinKeypairTypes.includes(parentPair.type);
|
|
218
267
|
const meta = {
|
|
219
268
|
name,
|
|
220
269
|
parentAddress: parentPair.address,
|
|
@@ -225,8 +274,8 @@ export const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
225
274
|
if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
|
|
226
275
|
meta.tonContractVersion = parentPair.ton.contractVersion;
|
|
227
276
|
}
|
|
228
|
-
if (derivationPath && (isEvm || isTon || isCardano)) {
|
|
229
|
-
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : parentPair.cardano.deriveCustom(derivationPath, meta);
|
|
277
|
+
if (derivationPath && (isEvm || isTon || isCardano || isBitcoin)) {
|
|
278
|
+
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : isCardano ? parentPair.cardano.deriveCustom(derivationPath, meta) : parentPair.bitcoin.deriveCustom(derivationPath, meta);
|
|
230
279
|
} else {
|
|
231
280
|
return parentPair.substrate.derive(suri, meta);
|
|
232
281
|
}
|
|
@@ -88,6 +88,8 @@ export const findUnifiedNextDerive = (proxyId, accounts) => {
|
|
|
88
88
|
index++;
|
|
89
89
|
} else if (currentDepth === 0 && deriveIndex === 0 && index > deriveIndex) {
|
|
90
90
|
// Special case for the first account on the root
|
|
91
|
+
} else if (deriveIndex === index - 1) {
|
|
92
|
+
// Special case, increased index before that, ex: 1/0, 1/1, 1/2
|
|
91
93
|
} else {
|
|
92
94
|
break;
|
|
93
95
|
}
|
|
@@ -3,6 +3,7 @@ import { KeypairType, SubstrateKeypairType } from '@subwallet/keyring/types';
|
|
|
3
3
|
export declare const validateUnifiedDerivationPath: (raw: string) => DerivePathInfo | undefined;
|
|
4
4
|
export declare const validateEvmDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
5
5
|
export declare const validateTonDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
6
|
+
export declare const validateBitcoinDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
6
7
|
export declare const validateCardanoDerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
7
8
|
export declare const validateSr25519DerivationPath: (raw: string) => IDerivePathInfo_ | undefined;
|
|
8
9
|
export declare const validateOtherSubstrateDerivationPath: (raw: string, type: Exclude<SubstrateKeypairType, 'sr25519'>) => IDerivePathInfo_ | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { BitcoinKeypairTypes } from '@subwallet/keyring/types';
|
|
4
5
|
export const validateUnifiedDerivationPath = raw => {
|
|
5
6
|
const reg = /^\/\/(\d+)(\/\/\d+)?$/;
|
|
6
7
|
if (raw.match(reg)) {
|
|
@@ -96,6 +97,66 @@ export const validateTonDerivationPath = raw => {
|
|
|
96
97
|
return undefined;
|
|
97
98
|
}
|
|
98
99
|
};
|
|
100
|
+
export const validateBitcoinDerivationPath = raw => {
|
|
101
|
+
const reg = /^m\/(44|84|86)'\/([01])'\/(\d+)'\/0\/0(\/\d+)?$/;
|
|
102
|
+
if (raw.match(reg)) {
|
|
103
|
+
const [, proposal, slip44, firstIndex, secondData] = raw.match(reg);
|
|
104
|
+
const first = parseInt(firstIndex, 10);
|
|
105
|
+
const autoIndexes = [first];
|
|
106
|
+
let depth;
|
|
107
|
+
let suri = `//${first}`;
|
|
108
|
+
let type;
|
|
109
|
+
if (slip44 === '0') {
|
|
110
|
+
switch (proposal) {
|
|
111
|
+
case '44':
|
|
112
|
+
type = 'bitcoin-44';
|
|
113
|
+
break;
|
|
114
|
+
case '84':
|
|
115
|
+
type = 'bitcoin-84';
|
|
116
|
+
break;
|
|
117
|
+
case '86':
|
|
118
|
+
type = 'bitcoin-86';
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
} else if (slip44 === '1') {
|
|
122
|
+
switch (proposal) {
|
|
123
|
+
case '44':
|
|
124
|
+
type = 'bittest-44';
|
|
125
|
+
break;
|
|
126
|
+
case '84':
|
|
127
|
+
type = 'bittest-84';
|
|
128
|
+
break;
|
|
129
|
+
case '86':
|
|
130
|
+
type = 'bittest-86';
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
if (!type) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
if (first === 0) {
|
|
138
|
+
depth = 0;
|
|
139
|
+
} else {
|
|
140
|
+
depth = 1;
|
|
141
|
+
}
|
|
142
|
+
if (secondData) {
|
|
143
|
+
const [, secondIndex] = secondData.match(/\/(\d+)/);
|
|
144
|
+
const second = parseInt(secondIndex, 10);
|
|
145
|
+
autoIndexes.push(second);
|
|
146
|
+
depth = 2;
|
|
147
|
+
suri += `//${second}`;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
depth,
|
|
151
|
+
type,
|
|
152
|
+
suri,
|
|
153
|
+
derivationPath: raw,
|
|
154
|
+
autoIndexes
|
|
155
|
+
};
|
|
156
|
+
} else {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
99
160
|
export const validateCardanoDerivationPath = raw => {
|
|
100
161
|
const reg = /^m\/1852'\/1815'\/(\d+)'(\/\d+')?$/;
|
|
101
162
|
if (raw.match(reg)) {
|
|
@@ -189,10 +250,16 @@ export const validateDerivationPath = (raw, type) => {
|
|
|
189
250
|
return validateOtherSubstrateDerivationPath(raw, type);
|
|
190
251
|
} else if (type === 'cardano') {
|
|
191
252
|
return validateCardanoDerivationPath(raw);
|
|
253
|
+
} else if (BitcoinKeypairTypes.includes(type)) {
|
|
254
|
+
const rs = validateBitcoinDerivationPath(raw);
|
|
255
|
+
if (rs && rs.type === type) {
|
|
256
|
+
return rs;
|
|
257
|
+
}
|
|
258
|
+
return undefined;
|
|
192
259
|
} else {
|
|
193
260
|
return undefined;
|
|
194
261
|
}
|
|
195
262
|
} else {
|
|
196
|
-
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw);
|
|
263
|
+
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw) || validateBitcoinDerivationPath(raw);
|
|
197
264
|
}
|
|
198
265
|
};
|
|
@@ -5,7 +5,7 @@ import { KeypairType, KeyringPair, KeyringPair$Meta } from '@subwallet/keyring/t
|
|
|
5
5
|
import { SingleAddress, SubjectInfo } from '@subwallet/ui-keyring/observable/types';
|
|
6
6
|
export declare const createAccountProxyId: (_suri: string, derivationPath?: string) => `0x${string}`;
|
|
7
7
|
export declare const getAccountChainTypeFromKeypairType: (type: KeypairType) => AccountChainType;
|
|
8
|
-
export declare const getDefaultKeypairTypeFromAccountChainType: (type: AccountChainType) => KeypairType;
|
|
8
|
+
export declare const getDefaultKeypairTypeFromAccountChainType: (type: AccountChainType) => KeypairType[];
|
|
9
9
|
export declare const getAccountSignMode: (address: string, _meta?: KeyringPair$Meta) => AccountSignMode;
|
|
10
10
|
export declare const getAccountActions: (signMode: AccountSignMode, networkType: AccountChainType, type: KeypairType, _meta?: KeyringPair$Meta, parentAccount?: AccountJson) => AccountActions[];
|
|
11
11
|
export declare const getAccountTransactionActions: (signMode: AccountSignMode, networkType: AccountChainType, type?: KeypairType, _meta?: KeyringPair$Meta, _specialNetwork?: string) => ExtrinsicType[];
|
|
@@ -37,15 +37,15 @@ export const getAccountChainTypeFromKeypairType = type => {
|
|
|
37
37
|
};
|
|
38
38
|
export const getDefaultKeypairTypeFromAccountChainType = type => {
|
|
39
39
|
if (type === AccountChainType.ETHEREUM) {
|
|
40
|
-
return 'ethereum';
|
|
40
|
+
return ['ethereum'];
|
|
41
41
|
} else if (type === AccountChainType.TON) {
|
|
42
|
-
return 'ton';
|
|
42
|
+
return ['ton'];
|
|
43
43
|
} else if (type === AccountChainType.BITCOIN) {
|
|
44
|
-
return 'bitcoin-84';
|
|
44
|
+
return ['bitcoin-44', 'bitcoin-84', 'bitcoin-86', 'bittest-44', 'bittest-84', 'bittest-86'];
|
|
45
45
|
} else if (type === AccountChainType.CARDANO) {
|
|
46
|
-
return 'cardano';
|
|
46
|
+
return ['cardano'];
|
|
47
47
|
} else {
|
|
48
|
-
return 'sr25519';
|
|
48
|
+
return ['sr25519'];
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
51
|
export const getAccountSignMode = (address, _meta) => {
|
|
@@ -162,6 +162,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
162
162
|
return [...BASE_TRANSFER_ACTIONS];
|
|
163
163
|
case AccountChainType.CARDANO:
|
|
164
164
|
return [...BASE_TRANSFER_ACTIONS];
|
|
165
|
+
case AccountChainType.BITCOIN:
|
|
166
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
165
167
|
}
|
|
166
168
|
} else if (signMode === AccountSignMode.QR) {
|
|
167
169
|
switch (networkType) {
|
|
@@ -173,6 +175,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
173
175
|
return [];
|
|
174
176
|
case AccountChainType.CARDANO:
|
|
175
177
|
return [];
|
|
178
|
+
case AccountChainType.BITCOIN:
|
|
179
|
+
return [];
|
|
176
180
|
}
|
|
177
181
|
} else if (signMode === AccountSignMode.GENERIC_LEDGER) {
|
|
178
182
|
switch (networkType) {
|
|
@@ -190,6 +194,8 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
190
194
|
return [...BASE_TRANSFER_ACTIONS];
|
|
191
195
|
case AccountChainType.CARDANO:
|
|
192
196
|
return [];
|
|
197
|
+
case AccountChainType.BITCOIN:
|
|
198
|
+
return [];
|
|
193
199
|
}
|
|
194
200
|
} else if (signMode === AccountSignMode.LEGACY_LEDGER) {
|
|
195
201
|
// Only for Substrate
|
package/utils/auth.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { getKeypairTypeByAddress } from '@subwallet/keyring';
|
|
5
|
-
import { CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
5
|
+
import { BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
6
6
|
export const isAddressValidWithAuthType = (address, accountAuthTypes) => {
|
|
7
7
|
const keypairType = getKeypairTypeByAddress(address);
|
|
8
8
|
const validTypes = {
|
|
9
9
|
evm: EthereumKeypairTypes,
|
|
10
10
|
substrate: SubstrateKeypairTypes,
|
|
11
11
|
ton: TonKeypairTypes,
|
|
12
|
-
cardano: CardanoKeypairTypes
|
|
12
|
+
cardano: CardanoKeypairTypes,
|
|
13
|
+
bitcoin: BitcoinKeypairTypes
|
|
13
14
|
};
|
|
14
15
|
return !!(accountAuthTypes !== null && accountAuthTypes !== void 0 && accountAuthTypes.some(authType => {
|
|
15
16
|
var _validTypes$authType;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { _BitcoinApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { UtxoResponseItem } from '@subwallet/extension-base/types';
|
|
3
|
+
import BigN from 'bignumber.js';
|
|
4
|
+
export declare function getSizeInfo(payload: {
|
|
5
|
+
inputLength: number;
|
|
6
|
+
recipients: string[];
|
|
7
|
+
sender: string;
|
|
8
|
+
}): {
|
|
9
|
+
txVBytes: number;
|
|
10
|
+
txBytes: number;
|
|
11
|
+
txWeight: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function getSpendableAmount({ feeRate, recipients, sender, utxos }: {
|
|
14
|
+
utxos: UtxoResponseItem[];
|
|
15
|
+
feeRate: number;
|
|
16
|
+
recipients: string[];
|
|
17
|
+
sender: string;
|
|
18
|
+
}): {
|
|
19
|
+
spendableAmount: BigN;
|
|
20
|
+
fee: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const getTransferableBitcoinUtxos: (bitcoinApi: _BitcoinApi, address: string) => Promise<UtxoResponseItem[]>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { filteredOutTxsUtxos, getInscriptionUtxos, getRuneUtxos } from '@subwallet/extension-base/utils';
|
|
5
|
+
import { BitcoinAddressType } from '@subwallet/keyring/types';
|
|
6
|
+
import { BtcSizeFeeEstimator, getBitcoinAddressInfo, validateBitcoinAddress } from '@subwallet/keyring/utils';
|
|
7
|
+
import BigN from 'bignumber.js';
|
|
8
|
+
|
|
9
|
+
// Source: https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/utils.ts
|
|
10
|
+
export function getSizeInfo(payload) {
|
|
11
|
+
const {
|
|
12
|
+
inputLength,
|
|
13
|
+
recipients,
|
|
14
|
+
sender
|
|
15
|
+
} = payload;
|
|
16
|
+
const senderInfo = validateBitcoinAddress(sender) ? getBitcoinAddressInfo(sender) : null;
|
|
17
|
+
const inputAddressTypeWithFallback = senderInfo ? senderInfo.type : BitcoinAddressType.p2wpkh;
|
|
18
|
+
const outputMap = {};
|
|
19
|
+
for (const recipient of recipients) {
|
|
20
|
+
const recipientInfo = validateBitcoinAddress(recipient) ? getBitcoinAddressInfo(recipient) : null;
|
|
21
|
+
const outputAddressTypeWithFallback = recipientInfo ? recipientInfo.type : BitcoinAddressType.p2wpkh;
|
|
22
|
+
const outputKey = outputAddressTypeWithFallback + '_output_count';
|
|
23
|
+
if (outputMap[outputKey]) {
|
|
24
|
+
outputMap[outputKey]++;
|
|
25
|
+
} else {
|
|
26
|
+
outputMap[outputKey] = 1;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const txSizer = new BtcSizeFeeEstimator();
|
|
30
|
+
return txSizer.calcTxSize({
|
|
31
|
+
input_script: inputAddressTypeWithFallback,
|
|
32
|
+
input_count: inputLength,
|
|
33
|
+
...outputMap
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/utils.ts
|
|
38
|
+
export function getSpendableAmount({
|
|
39
|
+
feeRate,
|
|
40
|
+
recipients,
|
|
41
|
+
sender,
|
|
42
|
+
utxos
|
|
43
|
+
}) {
|
|
44
|
+
const balance = utxos.map(utxo => utxo.value).reduce((prevVal, curVal) => prevVal + curVal, 0);
|
|
45
|
+
const size = getSizeInfo({
|
|
46
|
+
inputLength: utxos.length,
|
|
47
|
+
recipients,
|
|
48
|
+
sender
|
|
49
|
+
});
|
|
50
|
+
const fee = Math.ceil(size.txVBytes * feeRate);
|
|
51
|
+
const bigNumberBalance = new BigN(balance);
|
|
52
|
+
return {
|
|
53
|
+
spendableAmount: BigN.max(0, bigNumberBalance.minus(fee)),
|
|
54
|
+
fee
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export const getTransferableBitcoinUtxos = async (bitcoinApi, address) => {
|
|
58
|
+
try {
|
|
59
|
+
const [utxos, runeTxsUtxos, inscriptionUtxos] = await Promise.all([bitcoinApi.api.getUtxos(address).catch(error => {
|
|
60
|
+
console.log('Error fetching UTXOs:', error);
|
|
61
|
+
return [];
|
|
62
|
+
}), getRuneUtxos(bitcoinApi, address).catch(error => {
|
|
63
|
+
console.log('Error fetching Rune UTXOs:', error);
|
|
64
|
+
return [];
|
|
65
|
+
}), getInscriptionUtxos(bitcoinApi, address).catch(error => {
|
|
66
|
+
console.log('Error fetching Inscription UTXOs:', error);
|
|
67
|
+
return [];
|
|
68
|
+
})]);
|
|
69
|
+
let filteredUtxos;
|
|
70
|
+
if (!utxos || !utxos.length) {
|
|
71
|
+
return [];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// filter out pending utxos
|
|
75
|
+
// filteredUtxos = filterOutPendingTxsUtxos(utxos);
|
|
76
|
+
|
|
77
|
+
// filter out rune utxos
|
|
78
|
+
filteredUtxos = filteredOutTxsUtxos(utxos, runeTxsUtxos);
|
|
79
|
+
|
|
80
|
+
// filter out dust utxos
|
|
81
|
+
// filter out inscription utxos
|
|
82
|
+
filteredUtxos = filteredOutTxsUtxos(utxos, inscriptionUtxos);
|
|
83
|
+
return filteredUtxos;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
console.log('Error while fetching Bitcoin balances', error);
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export const combineBitcoinFee = (feeInfo, feeOptions, feeCustom) => {
|
|
5
|
+
if (feeOptions && feeOptions !== 'custom') {
|
|
6
|
+
var _feeInfo$options;
|
|
7
|
+
return (_feeInfo$options = feeInfo.options) === null || _feeInfo$options === void 0 ? void 0 : _feeInfo$options[feeOptions];
|
|
8
|
+
} else if (feeOptions === 'custom' && feeCustom) {
|
|
9
|
+
return feeCustom;
|
|
10
|
+
} else {
|
|
11
|
+
var _feeInfo$options2;
|
|
12
|
+
return (_feeInfo$options2 = feeInfo.options) === null || _feeInfo$options2 === void 0 ? void 0 : _feeInfo$options2[feeInfo.options.default];
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { _BitcoinApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { DetermineUtxosForSpendArgs, UtxoResponseItem } from '@subwallet/extension-base/types';
|
|
3
|
+
export declare function filterUneconomicalUtxos({ feeRate, recipients, sender, utxos }: {
|
|
4
|
+
utxos: UtxoResponseItem[];
|
|
5
|
+
feeRate: number;
|
|
6
|
+
sender: string;
|
|
7
|
+
recipients: string[];
|
|
8
|
+
}): UtxoResponseItem[];
|
|
9
|
+
export declare function determineUtxosForSpendAll({ feeRate, recipient, sender, utxos }: DetermineUtxosForSpendArgs): {
|
|
10
|
+
inputs: UtxoResponseItem[];
|
|
11
|
+
outputs: {
|
|
12
|
+
value: number;
|
|
13
|
+
address: string;
|
|
14
|
+
}[];
|
|
15
|
+
size: number;
|
|
16
|
+
fee: number;
|
|
17
|
+
isCustomFeeRate: boolean;
|
|
18
|
+
};
|
|
19
|
+
export declare function determineUtxosForSpend({ amount, feeRate, recipient, sender, utxos }: DetermineUtxosForSpendArgs): {
|
|
20
|
+
filteredUtxos: UtxoResponseItem[];
|
|
21
|
+
inputs: UtxoResponseItem[];
|
|
22
|
+
outputs: {
|
|
23
|
+
value: number;
|
|
24
|
+
address: string;
|
|
25
|
+
}[];
|
|
26
|
+
size: number;
|
|
27
|
+
fee: number;
|
|
28
|
+
isCustomFeeRate: boolean;
|
|
29
|
+
};
|
|
30
|
+
export declare function filterOutPendingTxsUtxos(utxos: UtxoResponseItem[]): UtxoResponseItem[];
|
|
31
|
+
export declare function filteredOutTxsUtxos(allTxsUtxos: UtxoResponseItem[], filteredOutTxsUtxos: UtxoResponseItem[]): UtxoResponseItem[];
|
|
32
|
+
export declare function getRuneUtxos(bitcoinApi: _BitcoinApi, address: string): Promise<UtxoResponseItem[]>;
|
|
33
|
+
export declare function getInscriptionUtxos(bitcoinApi: _BitcoinApi, address: string): Promise<UtxoResponseItem[]>;
|