@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
|
@@ -10,12 +10,12 @@ exports.isAccountAll = isAccountAll;
|
|
|
10
10
|
exports.modifyAccountName = void 0;
|
|
11
11
|
exports.quickFormatAddressToCompare = quickFormatAddressToCompare;
|
|
12
12
|
exports.reformatAddress = reformatAddress;
|
|
13
|
-
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
14
13
|
var _constants = require("@subwallet/extension-base/constants");
|
|
15
14
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
16
15
|
var _types = require("@subwallet/extension-base/types");
|
|
17
16
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
18
17
|
var _keyring = require("@subwallet/keyring");
|
|
18
|
+
var _validate = require("@subwallet/keyring/utils/address/validate");
|
|
19
19
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
20
20
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
21
21
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -68,20 +68,22 @@ const getAccountChainTypeForAddress = address => {
|
|
|
68
68
|
return (0, _utils2.getAccountChainTypeFromKeypairType)(type);
|
|
69
69
|
};
|
|
70
70
|
exports.getAccountChainTypeForAddress = getAccountChainTypeForAddress;
|
|
71
|
-
function
|
|
72
|
-
|
|
71
|
+
// TODO: Recheck the usage of this function for Bitcoin; it is currently applied to history.
|
|
72
|
+
function getAddressesByChainType(addresses, chainTypes, chainInfo) {
|
|
73
|
+
const addressByChainTypeMap = getAddressesByChainTypeMap(addresses, chainInfo);
|
|
73
74
|
return chainTypes.map(chainType => {
|
|
74
75
|
return addressByChainTypeMap[chainType];
|
|
75
76
|
}).flat(); // todo: recheck
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
function getAddressesByChainTypeMap(addresses) {
|
|
79
|
+
function getAddressesByChainTypeMap(addresses, chainInfo) {
|
|
79
80
|
const addressByChainType = {
|
|
80
81
|
substrate: [],
|
|
81
82
|
evm: [],
|
|
82
83
|
bitcoin: [],
|
|
83
84
|
ton: [],
|
|
84
|
-
cardano: []
|
|
85
|
+
cardano: [],
|
|
86
|
+
_bitcoin: []
|
|
85
87
|
};
|
|
86
88
|
addresses.forEach(address => {
|
|
87
89
|
if ((0, _utilCrypto.isEthereumAddress)(address)) {
|
|
@@ -89,7 +91,15 @@ function getAddressesByChainTypeMap(addresses) {
|
|
|
89
91
|
} else if ((0, _keyring.isTonAddress)(address)) {
|
|
90
92
|
addressByChainType.ton.push(address);
|
|
91
93
|
} else if ((0, _keyring.isBitcoinAddress)(address)) {
|
|
92
|
-
|
|
94
|
+
const addressInfo = (0, _validate.getBitcoinAddressInfo)(address);
|
|
95
|
+
if (chainInfo !== null && chainInfo !== void 0 && chainInfo.bitcoinInfo) {
|
|
96
|
+
const isNetworkMatch = addressInfo.network === chainInfo.bitcoinInfo.bitcoinNetwork;
|
|
97
|
+
if (isNetworkMatch) {
|
|
98
|
+
addressByChainType.bitcoin.push(address);
|
|
99
|
+
} else {
|
|
100
|
+
addressByChainType._bitcoin.push(address);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
93
103
|
} else if ((0, _keyring.isCardanoAddress)(address)) {
|
|
94
104
|
addressByChainType.cardano.push(address);
|
|
95
105
|
} else {
|
|
@@ -13,27 +13,50 @@ var _validate = require("../validate");
|
|
|
13
13
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
14
14
|
// SPDX-License-Identifier: Apache-2.0
|
|
15
15
|
|
|
16
|
+
const bitPathLv1 = "m/{proposal}'/{slip44}'/{firstIndex}'/0/0";
|
|
17
|
+
const bitPathLv2 = "m/{proposal}'/{slip44}'/{firstIndex}'/0/0/{secondIndex}";
|
|
18
|
+
const getBitLv1DerivePathFunction = (slip44, proposal) => {
|
|
19
|
+
return bitPathLv1.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
|
|
20
|
+
};
|
|
21
|
+
const getBitLv2DerivePathFunction = (slip44, proposal) => {
|
|
22
|
+
return bitPathLv2.replace('{proposal}', proposal.toString()).replace('{slip44}', slip44.toString());
|
|
23
|
+
};
|
|
24
|
+
const level1DerivationPathMap = {
|
|
25
|
+
ethereum: "m/44'/60'/0'/0/{firstIndex}",
|
|
26
|
+
ton: "m/44'/607'/{firstIndex}'",
|
|
27
|
+
cardano: "m/1852'/1815'/{firstIndex}'",
|
|
28
|
+
'bitcoin-44': getBitLv1DerivePathFunction(0, 44),
|
|
29
|
+
'bitcoin-84': getBitLv1DerivePathFunction(0, 84),
|
|
30
|
+
'bitcoin-86': getBitLv1DerivePathFunction(0, 86),
|
|
31
|
+
'bittest-44': getBitLv1DerivePathFunction(1, 44),
|
|
32
|
+
'bittest-84': getBitLv1DerivePathFunction(1, 84),
|
|
33
|
+
'bittest-86': getBitLv1DerivePathFunction(1, 86)
|
|
34
|
+
};
|
|
35
|
+
const level2DerivationPathMap = {
|
|
36
|
+
ethereum: "m/44'/60'/0'/0/{firstIndex}/{secondIndex}",
|
|
37
|
+
ton: "m/44'/607'/{firstIndex}'/{secondIndex}'",
|
|
38
|
+
cardano: "m/1852'/1815'/{firstIndex}'/{secondIndex}'",
|
|
39
|
+
'bitcoin-44': getBitLv2DerivePathFunction(0, 44),
|
|
40
|
+
'bitcoin-84': getBitLv2DerivePathFunction(0, 84),
|
|
41
|
+
'bitcoin-86': getBitLv2DerivePathFunction(0, 86),
|
|
42
|
+
'bittest-44': getBitLv2DerivePathFunction(1, 44),
|
|
43
|
+
'bittest-84': getBitLv2DerivePathFunction(1, 84),
|
|
44
|
+
'bittest-86': getBitLv2DerivePathFunction(1, 86)
|
|
45
|
+
};
|
|
16
46
|
const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
17
47
|
const reg = /^\/\/(\d+)(\/\/\d+)?$/;
|
|
18
48
|
if (suri.match(reg)) {
|
|
19
49
|
const [, firstIndex, secondData] = suri.match(reg);
|
|
20
|
-
const first = parseInt(firstIndex, 10);
|
|
21
50
|
if (secondData) {
|
|
22
51
|
const [, secondIndex] = secondData.match(/\/\/(\d+)/);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return `m/44'/607'/${first}'/${secondIndex}'`;
|
|
27
|
-
} else if (type === 'cardano') {
|
|
28
|
-
return `m/1852'/1815'/${first}'/${secondIndex}'`;
|
|
52
|
+
const path = level2DerivationPathMap[type];
|
|
53
|
+
if (path) {
|
|
54
|
+
return path.replace('{firstIndex}', firstIndex).replace('{secondIndex}', secondIndex);
|
|
29
55
|
}
|
|
30
56
|
} else {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return `m/44'/607'/${first}'`;
|
|
35
|
-
} else if (type === 'cardano') {
|
|
36
|
-
return `m/1852'/1815'/${first}'`;
|
|
57
|
+
const path = level1DerivationPathMap[type];
|
|
58
|
+
if (path) {
|
|
59
|
+
return path.replace('{firstIndex}', firstIndex);
|
|
37
60
|
}
|
|
38
61
|
}
|
|
39
62
|
if (_types.SubstrateKeypairTypes.includes(type)) {
|
|
@@ -43,6 +66,33 @@ const parseUnifiedSuriToDerivationPath = (suri, type) => {
|
|
|
43
66
|
return '';
|
|
44
67
|
};
|
|
45
68
|
exports.parseUnifiedSuriToDerivationPath = parseUnifiedSuriToDerivationPath;
|
|
69
|
+
const validateNonSubstrateDerivationPath = (derivePath, type) => {
|
|
70
|
+
let validateTypeRs;
|
|
71
|
+
switch (type) {
|
|
72
|
+
case 'ethereum':
|
|
73
|
+
validateTypeRs = (0, _validate.validateEvmDerivationPath)(derivePath);
|
|
74
|
+
break;
|
|
75
|
+
case 'ton':
|
|
76
|
+
validateTypeRs = (0, _validate.validateTonDerivationPath)(derivePath);
|
|
77
|
+
break;
|
|
78
|
+
case 'cardano':
|
|
79
|
+
validateTypeRs = (0, _validate.validateCardanoDerivationPath)(derivePath);
|
|
80
|
+
break;
|
|
81
|
+
case 'bitcoin-44':
|
|
82
|
+
case 'bitcoin-84':
|
|
83
|
+
case 'bitcoin-86':
|
|
84
|
+
case 'bittest-44':
|
|
85
|
+
case 'bittest-84':
|
|
86
|
+
case 'bittest-86':
|
|
87
|
+
validateTypeRs = (0, _validate.validateBitcoinDerivationPath)(derivePath);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
if (validateTypeRs && validateTypeRs.type === type) {
|
|
91
|
+
return validateTypeRs;
|
|
92
|
+
} else {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
46
96
|
const getSoloDerivationInfo = function (type) {
|
|
47
97
|
let metadata = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
48
98
|
const {
|
|
@@ -52,8 +102,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
52
102
|
} = metadata;
|
|
53
103
|
if (suri) {
|
|
54
104
|
if (derivePath) {
|
|
55
|
-
const
|
|
56
|
-
const validateTypeRs = validateTypeFunc(derivePath);
|
|
105
|
+
const validateTypeRs = validateNonSubstrateDerivationPath(derivePath, type);
|
|
57
106
|
if (validateTypeRs) {
|
|
58
107
|
return {
|
|
59
108
|
suri: validateTypeRs.suri,
|
|
@@ -109,8 +158,7 @@ const getSoloDerivationInfo = function (type) {
|
|
|
109
158
|
}
|
|
110
159
|
} else {
|
|
111
160
|
if (derivePath) {
|
|
112
|
-
const
|
|
113
|
-
const validateTypeRs = validateTypeFunc(derivePath);
|
|
161
|
+
const validateTypeRs = validateNonSubstrateDerivationPath(derivePath, type);
|
|
114
162
|
if (validateTypeRs) {
|
|
115
163
|
return {
|
|
116
164
|
suri: validateTypeRs.suri,
|
|
@@ -229,6 +277,7 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
229
277
|
const isEvm = _types.EthereumKeypairTypes.includes(parentPair.type);
|
|
230
278
|
const isTon = parentPair.type === 'ton';
|
|
231
279
|
const isCardano = parentPair.type === 'cardano';
|
|
280
|
+
const isBitcoin = _types.BitcoinKeypairTypes.includes(parentPair.type);
|
|
232
281
|
const meta = {
|
|
233
282
|
name,
|
|
234
283
|
parentAddress: parentPair.address,
|
|
@@ -239,8 +288,8 @@ const derivePair = (parentPair, name, suri, derivationPath) => {
|
|
|
239
288
|
if (isTon && (_parentPair$ton = parentPair.ton) !== null && _parentPair$ton !== void 0 && _parentPair$ton.contractVersion) {
|
|
240
289
|
meta.tonContractVersion = parentPair.ton.contractVersion;
|
|
241
290
|
}
|
|
242
|
-
if (derivationPath && (isEvm || isTon || isCardano)) {
|
|
243
|
-
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : parentPair.cardano.deriveCustom(derivationPath, meta);
|
|
291
|
+
if (derivationPath && (isEvm || isTon || isCardano || isBitcoin)) {
|
|
292
|
+
return isEvm ? parentPair.evm.deriveCustom(derivationPath, meta) : isTon ? parentPair.ton.deriveCustom(derivationPath, meta) : isCardano ? parentPair.cardano.deriveCustom(derivationPath, meta) : parentPair.bitcoin.deriveCustom(derivationPath, meta);
|
|
244
293
|
} else {
|
|
245
294
|
return parentPair.substrate.derive(suri, meta);
|
|
246
295
|
}
|
|
@@ -97,6 +97,8 @@ const findUnifiedNextDerive = (proxyId, accounts) => {
|
|
|
97
97
|
index++;
|
|
98
98
|
} else if (currentDepth === 0 && deriveIndex === 0 && index > deriveIndex) {
|
|
99
99
|
// Special case for the first account on the root
|
|
100
|
+
} else if (deriveIndex === index - 1) {
|
|
101
|
+
// Special case, increased index before that, ex: 1/0, 1/1, 1/2
|
|
100
102
|
} else {
|
|
101
103
|
break;
|
|
102
104
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validateUnifiedDerivationPath = exports.validateTonDerivationPath = exports.validateSr25519DerivationPath = exports.validateOtherSubstrateDerivationPath = exports.validateEvmDerivationPath = exports.validateDerivationPath = exports.validateCardanoDerivationPath = void 0;
|
|
6
|
+
exports.validateUnifiedDerivationPath = exports.validateTonDerivationPath = exports.validateSr25519DerivationPath = exports.validateOtherSubstrateDerivationPath = exports.validateEvmDerivationPath = exports.validateDerivationPath = exports.validateCardanoDerivationPath = exports.validateBitcoinDerivationPath = void 0;
|
|
7
|
+
var _types = require("@subwallet/keyring/types");
|
|
7
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
10
|
|
|
@@ -105,6 +106,67 @@ const validateTonDerivationPath = raw => {
|
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
108
|
exports.validateTonDerivationPath = validateTonDerivationPath;
|
|
109
|
+
const validateBitcoinDerivationPath = raw => {
|
|
110
|
+
const reg = /^m\/(44|84|86)'\/([01])'\/(\d+)'\/0\/0(\/\d+)?$/;
|
|
111
|
+
if (raw.match(reg)) {
|
|
112
|
+
const [, proposal, slip44, firstIndex, secondData] = raw.match(reg);
|
|
113
|
+
const first = parseInt(firstIndex, 10);
|
|
114
|
+
const autoIndexes = [first];
|
|
115
|
+
let depth;
|
|
116
|
+
let suri = `//${first}`;
|
|
117
|
+
let type;
|
|
118
|
+
if (slip44 === '0') {
|
|
119
|
+
switch (proposal) {
|
|
120
|
+
case '44':
|
|
121
|
+
type = 'bitcoin-44';
|
|
122
|
+
break;
|
|
123
|
+
case '84':
|
|
124
|
+
type = 'bitcoin-84';
|
|
125
|
+
break;
|
|
126
|
+
case '86':
|
|
127
|
+
type = 'bitcoin-86';
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
} else if (slip44 === '1') {
|
|
131
|
+
switch (proposal) {
|
|
132
|
+
case '44':
|
|
133
|
+
type = 'bittest-44';
|
|
134
|
+
break;
|
|
135
|
+
case '84':
|
|
136
|
+
type = 'bittest-84';
|
|
137
|
+
break;
|
|
138
|
+
case '86':
|
|
139
|
+
type = 'bittest-86';
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!type) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
if (first === 0) {
|
|
147
|
+
depth = 0;
|
|
148
|
+
} else {
|
|
149
|
+
depth = 1;
|
|
150
|
+
}
|
|
151
|
+
if (secondData) {
|
|
152
|
+
const [, secondIndex] = secondData.match(/\/(\d+)/);
|
|
153
|
+
const second = parseInt(secondIndex, 10);
|
|
154
|
+
autoIndexes.push(second);
|
|
155
|
+
depth = 2;
|
|
156
|
+
suri += `//${second}`;
|
|
157
|
+
}
|
|
158
|
+
return {
|
|
159
|
+
depth,
|
|
160
|
+
type,
|
|
161
|
+
suri,
|
|
162
|
+
derivationPath: raw,
|
|
163
|
+
autoIndexes
|
|
164
|
+
};
|
|
165
|
+
} else {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
exports.validateBitcoinDerivationPath = validateBitcoinDerivationPath;
|
|
108
170
|
const validateCardanoDerivationPath = raw => {
|
|
109
171
|
const reg = /^m\/1852'\/1815'\/(\d+)'(\/\d+')?$/;
|
|
110
172
|
if (raw.match(reg)) {
|
|
@@ -201,11 +263,17 @@ const validateDerivationPath = (raw, type) => {
|
|
|
201
263
|
return validateOtherSubstrateDerivationPath(raw, type);
|
|
202
264
|
} else if (type === 'cardano') {
|
|
203
265
|
return validateCardanoDerivationPath(raw);
|
|
266
|
+
} else if (_types.BitcoinKeypairTypes.includes(type)) {
|
|
267
|
+
const rs = validateBitcoinDerivationPath(raw);
|
|
268
|
+
if (rs && rs.type === type) {
|
|
269
|
+
return rs;
|
|
270
|
+
}
|
|
271
|
+
return undefined;
|
|
204
272
|
} else {
|
|
205
273
|
return undefined;
|
|
206
274
|
}
|
|
207
275
|
} else {
|
|
208
|
-
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw);
|
|
276
|
+
return validateUnifiedDerivationPath(raw) || validateEvmDerivationPath(raw) || validateTonDerivationPath(raw) || validateSr25519DerivationPath(raw) || validateCardanoDerivationPath(raw) || validateBitcoinDerivationPath(raw);
|
|
209
277
|
}
|
|
210
278
|
};
|
|
211
279
|
exports.validateDerivationPath = validateDerivationPath;
|
|
@@ -45,15 +45,15 @@ const getAccountChainTypeFromKeypairType = type => {
|
|
|
45
45
|
exports.getAccountChainTypeFromKeypairType = getAccountChainTypeFromKeypairType;
|
|
46
46
|
const getDefaultKeypairTypeFromAccountChainType = type => {
|
|
47
47
|
if (type === _types2.AccountChainType.ETHEREUM) {
|
|
48
|
-
return 'ethereum';
|
|
48
|
+
return ['ethereum'];
|
|
49
49
|
} else if (type === _types2.AccountChainType.TON) {
|
|
50
|
-
return 'ton';
|
|
50
|
+
return ['ton'];
|
|
51
51
|
} else if (type === _types2.AccountChainType.BITCOIN) {
|
|
52
|
-
return 'bitcoin-84';
|
|
52
|
+
return ['bitcoin-44', 'bitcoin-84', 'bitcoin-86', 'bittest-44', 'bittest-84', 'bittest-86'];
|
|
53
53
|
} else if (type === _types2.AccountChainType.CARDANO) {
|
|
54
|
-
return 'cardano';
|
|
54
|
+
return ['cardano'];
|
|
55
55
|
} else {
|
|
56
|
-
return 'sr25519';
|
|
56
|
+
return ['sr25519'];
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
59
|
exports.getDefaultKeypairTypeFromAccountChainType = getDefaultKeypairTypeFromAccountChainType;
|
|
@@ -173,6 +173,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
173
173
|
return [...BASE_TRANSFER_ACTIONS];
|
|
174
174
|
case _types2.AccountChainType.CARDANO:
|
|
175
175
|
return [...BASE_TRANSFER_ACTIONS];
|
|
176
|
+
case _types2.AccountChainType.BITCOIN:
|
|
177
|
+
return [...BASE_TRANSFER_ACTIONS];
|
|
176
178
|
}
|
|
177
179
|
} else if (signMode === _types2.AccountSignMode.QR) {
|
|
178
180
|
switch (networkType) {
|
|
@@ -184,6 +186,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
184
186
|
return [];
|
|
185
187
|
case _types2.AccountChainType.CARDANO:
|
|
186
188
|
return [];
|
|
189
|
+
case _types2.AccountChainType.BITCOIN:
|
|
190
|
+
return [];
|
|
187
191
|
}
|
|
188
192
|
} else if (signMode === _types2.AccountSignMode.GENERIC_LEDGER) {
|
|
189
193
|
switch (networkType) {
|
|
@@ -201,6 +205,8 @@ const getAccountTransactionActions = (signMode, networkType, type, _meta, _speci
|
|
|
201
205
|
return [...BASE_TRANSFER_ACTIONS];
|
|
202
206
|
case _types2.AccountChainType.CARDANO:
|
|
203
207
|
return [];
|
|
208
|
+
case _types2.AccountChainType.BITCOIN:
|
|
209
|
+
return [];
|
|
204
210
|
}
|
|
205
211
|
} else if (signMode === _types2.AccountSignMode.LEGACY_LEDGER) {
|
|
206
212
|
// Only for Substrate
|
package/cjs/utils/auth.js
CHANGED
|
@@ -15,7 +15,8 @@ const isAddressValidWithAuthType = (address, accountAuthTypes) => {
|
|
|
15
15
|
evm: _types.EthereumKeypairTypes,
|
|
16
16
|
substrate: _types.SubstrateKeypairTypes,
|
|
17
17
|
ton: _types.TonKeypairTypes,
|
|
18
|
-
cardano: _types.CardanoKeypairTypes
|
|
18
|
+
cardano: _types.CardanoKeypairTypes,
|
|
19
|
+
bitcoin: _types.BitcoinKeypairTypes
|
|
19
20
|
};
|
|
20
21
|
return !!(accountAuthTypes !== null && accountAuthTypes !== void 0 && accountAuthTypes.some(authType => {
|
|
21
22
|
var _validTypes$authType;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getSizeInfo = getSizeInfo;
|
|
8
|
+
exports.getSpendableAmount = getSpendableAmount;
|
|
9
|
+
exports.getTransferableBitcoinUtxos = void 0;
|
|
10
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
11
|
+
var _types = require("@subwallet/keyring/types");
|
|
12
|
+
var _utils2 = require("@subwallet/keyring/utils");
|
|
13
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
14
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
// Source: https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/utils.ts
|
|
18
|
+
function getSizeInfo(payload) {
|
|
19
|
+
const {
|
|
20
|
+
inputLength,
|
|
21
|
+
recipients,
|
|
22
|
+
sender
|
|
23
|
+
} = payload;
|
|
24
|
+
const senderInfo = (0, _utils2.validateBitcoinAddress)(sender) ? (0, _utils2.getBitcoinAddressInfo)(sender) : null;
|
|
25
|
+
const inputAddressTypeWithFallback = senderInfo ? senderInfo.type : _types.BitcoinAddressType.p2wpkh;
|
|
26
|
+
const outputMap = {};
|
|
27
|
+
for (const recipient of recipients) {
|
|
28
|
+
const recipientInfo = (0, _utils2.validateBitcoinAddress)(recipient) ? (0, _utils2.getBitcoinAddressInfo)(recipient) : null;
|
|
29
|
+
const outputAddressTypeWithFallback = recipientInfo ? recipientInfo.type : _types.BitcoinAddressType.p2wpkh;
|
|
30
|
+
const outputKey = outputAddressTypeWithFallback + '_output_count';
|
|
31
|
+
if (outputMap[outputKey]) {
|
|
32
|
+
outputMap[outputKey]++;
|
|
33
|
+
} else {
|
|
34
|
+
outputMap[outputKey] = 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const txSizer = new _utils2.BtcSizeFeeEstimator();
|
|
38
|
+
return txSizer.calcTxSize({
|
|
39
|
+
input_script: inputAddressTypeWithFallback,
|
|
40
|
+
input_count: inputLength,
|
|
41
|
+
...outputMap
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// https://github.com/leather-wallet/extension/blob/dev/src/app/common/transactions/bitcoin/utils.ts
|
|
46
|
+
function getSpendableAmount(_ref) {
|
|
47
|
+
let {
|
|
48
|
+
feeRate,
|
|
49
|
+
recipients,
|
|
50
|
+
sender,
|
|
51
|
+
utxos
|
|
52
|
+
} = _ref;
|
|
53
|
+
const balance = utxos.map(utxo => utxo.value).reduce((prevVal, curVal) => prevVal + curVal, 0);
|
|
54
|
+
const size = getSizeInfo({
|
|
55
|
+
inputLength: utxos.length,
|
|
56
|
+
recipients,
|
|
57
|
+
sender
|
|
58
|
+
});
|
|
59
|
+
const fee = Math.ceil(size.txVBytes * feeRate);
|
|
60
|
+
const bigNumberBalance = new _bignumber.default(balance);
|
|
61
|
+
return {
|
|
62
|
+
spendableAmount: _bignumber.default.max(0, bigNumberBalance.minus(fee)),
|
|
63
|
+
fee
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const getTransferableBitcoinUtxos = async (bitcoinApi, address) => {
|
|
67
|
+
try {
|
|
68
|
+
const [utxos, runeTxsUtxos, inscriptionUtxos] = await Promise.all([bitcoinApi.api.getUtxos(address).catch(error => {
|
|
69
|
+
console.log('Error fetching UTXOs:', error);
|
|
70
|
+
return [];
|
|
71
|
+
}), (0, _utils.getRuneUtxos)(bitcoinApi, address).catch(error => {
|
|
72
|
+
console.log('Error fetching Rune UTXOs:', error);
|
|
73
|
+
return [];
|
|
74
|
+
}), (0, _utils.getInscriptionUtxos)(bitcoinApi, address).catch(error => {
|
|
75
|
+
console.log('Error fetching Inscription UTXOs:', error);
|
|
76
|
+
return [];
|
|
77
|
+
})]);
|
|
78
|
+
let filteredUtxos;
|
|
79
|
+
if (!utxos || !utxos.length) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// filter out pending utxos
|
|
84
|
+
// filteredUtxos = filterOutPendingTxsUtxos(utxos);
|
|
85
|
+
|
|
86
|
+
// filter out rune utxos
|
|
87
|
+
filteredUtxos = (0, _utils.filteredOutTxsUtxos)(utxos, runeTxsUtxos);
|
|
88
|
+
|
|
89
|
+
// filter out dust utxos
|
|
90
|
+
// filter out inscription utxos
|
|
91
|
+
filteredUtxos = (0, _utils.filteredOutTxsUtxos)(utxos, inscriptionUtxos);
|
|
92
|
+
return filteredUtxos;
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.log('Error while fetching Bitcoin balances', error);
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
exports.getTransferableBitcoinUtxos = getTransferableBitcoinUtxos;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.combineBitcoinFee = void 0;
|
|
7
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
8
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
+
|
|
10
|
+
const combineBitcoinFee = (feeInfo, feeOptions, feeCustom) => {
|
|
11
|
+
if (feeOptions && feeOptions !== 'custom') {
|
|
12
|
+
var _feeInfo$options;
|
|
13
|
+
return (_feeInfo$options = feeInfo.options) === null || _feeInfo$options === void 0 ? void 0 : _feeInfo$options[feeOptions];
|
|
14
|
+
} else if (feeOptions === 'custom' && feeCustom) {
|
|
15
|
+
return feeCustom;
|
|
16
|
+
} else {
|
|
17
|
+
var _feeInfo$options2;
|
|
18
|
+
return (_feeInfo$options2 = feeInfo.options) === null || _feeInfo$options2 === void 0 ? void 0 : _feeInfo$options2[feeInfo.options.default];
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.combineBitcoinFee = combineBitcoinFee;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _common = require("./common");
|
|
7
|
+
Object.keys(_common).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _common[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _common[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _fee = require("./fee");
|
|
18
|
+
Object.keys(_fee).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _fee[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _fee[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _utxoManagement = require("./utxo-management");
|
|
29
|
+
Object.keys(_utxoManagement).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _utxoManagement[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _utxoManagement[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|