@subwallet/extension-base 1.3.41-0 → 1.3.42-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (196) hide show
  1. package/background/KoniTypes.d.ts +121 -4
  2. package/background/KoniTypes.js +18 -0
  3. package/background/errors/BitcoinProviderError.d.ts +6 -0
  4. package/background/errors/BitcoinProviderError.js +47 -0
  5. package/cjs/background/KoniTypes.js +20 -1
  6. package/cjs/background/errors/BitcoinProviderError.js +54 -0
  7. package/cjs/constants/bitcoin.js +22 -0
  8. package/cjs/constants/index.js +16 -1
  9. package/cjs/core/logic-validation/recipientAddress.js +9 -0
  10. package/cjs/core/logic-validation/transfer.js +25 -5
  11. package/cjs/core/types.js +1 -0
  12. package/cjs/core/utils.js +15 -1
  13. package/cjs/koni/background/handlers/Extension.js +59 -3
  14. package/cjs/koni/background/handlers/State.js +52 -11
  15. package/cjs/packageInfo.js +1 -1
  16. package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
  17. package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
  18. package/cjs/services/balance-service/index.js +32 -4
  19. package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
  20. package/cjs/services/balance-service/transfer/token.js +2 -0
  21. package/cjs/services/base/types.js +2 -0
  22. package/cjs/services/chain-service/constants.js +14 -3
  23. package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
  24. package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
  25. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
  26. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
  27. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
  28. package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
  29. package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  30. package/cjs/services/chain-service/index.js +27 -3
  31. package/cjs/services/chain-service/utils/index.js +57 -4
  32. package/cjs/services/chain-service/utils/patch.js +1 -1
  33. package/cjs/services/event-service/index.js +4 -0
  34. package/cjs/services/fee-service/service.js +8 -3
  35. package/cjs/services/hiro-service/index.js +96 -0
  36. package/cjs/services/hiro-service/utils/index.js +85 -0
  37. package/cjs/services/history-service/bitcoin-history.js +58 -0
  38. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  39. package/cjs/services/history-service/index.js +41 -3
  40. package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
  41. package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
  42. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  43. package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
  44. package/cjs/services/migration-service/scripts/index.js +3 -1
  45. package/cjs/services/request-service/handler/BitcoinRequestHandler.js +440 -0
  46. package/cjs/services/request-service/index.js +29 -3
  47. package/cjs/services/rune-service/index.js +105 -0
  48. package/cjs/services/transaction-service/helpers/index.js +7 -1
  49. package/cjs/services/transaction-service/index.js +136 -15
  50. package/cjs/services/transaction-service/utils.js +6 -3
  51. package/cjs/strategy/api-request-strategy/context/base.js +31 -0
  52. package/cjs/strategy/api-request-strategy/index.js +90 -0
  53. package/cjs/strategy/api-request-strategy/types.js +1 -0
  54. package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
  55. package/cjs/types/account/info/keyring.js +1 -1
  56. package/cjs/types/bitcoin.js +24 -0
  57. package/cjs/types/fee/bitcoin.js +1 -0
  58. package/cjs/types/fee/index.js +11 -0
  59. package/cjs/types/index.js +11 -0
  60. package/cjs/utils/account/analyze.js +3 -3
  61. package/cjs/utils/account/common.js +16 -6
  62. package/cjs/utils/account/derive/info/solo.js +68 -19
  63. package/cjs/utils/account/derive/info/unified.js +2 -0
  64. package/cjs/utils/account/derive/validate.js +70 -2
  65. package/cjs/utils/account/transform.js +11 -5
  66. package/cjs/utils/bitcoin/common.js +98 -0
  67. package/cjs/utils/bitcoin/fee.js +21 -0
  68. package/cjs/utils/bitcoin/index.js +38 -0
  69. package/cjs/utils/bitcoin/utxo-management.js +281 -0
  70. package/cjs/utils/fee/transfer.js +48 -0
  71. package/cjs/utils/index.js +15 -1
  72. package/constants/bitcoin.d.ts +3 -0
  73. package/constants/bitcoin.js +13 -0
  74. package/constants/index.d.ts +2 -0
  75. package/constants/index.js +3 -1
  76. package/core/logic-validation/recipientAddress.js +10 -1
  77. package/core/logic-validation/transfer.d.ts +2 -2
  78. package/core/logic-validation/transfer.js +27 -7
  79. package/core/types.d.ts +1 -0
  80. package/core/types.js +1 -0
  81. package/core/utils.d.ts +1 -0
  82. package/core/utils.js +15 -2
  83. package/koni/background/handlers/Extension.d.ts +2 -0
  84. package/koni/background/handlers/Extension.js +58 -4
  85. package/koni/background/handlers/State.d.ts +7 -3
  86. package/koni/background/handlers/State.js +52 -12
  87. package/package.json +144 -8
  88. package/packageInfo.js +1 -1
  89. package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
  90. package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
  91. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  92. package/services/balance-service/helpers/subscribe/index.js +20 -8
  93. package/services/balance-service/index.d.ts +2 -0
  94. package/services/balance-service/index.js +32 -4
  95. package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
  96. package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
  97. package/services/balance-service/transfer/token.js +2 -0
  98. package/services/base/types.d.ts +2 -0
  99. package/services/base/types.js +2 -0
  100. package/services/chain-service/constants.d.ts +6 -0
  101. package/services/chain-service/constants.js +8 -2
  102. package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
  103. package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
  104. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
  105. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
  106. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
  107. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
  108. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
  109. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
  110. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
  111. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
  112. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
  113. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
  114. package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
  115. package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  116. package/services/chain-service/index.d.ts +3 -0
  117. package/services/chain-service/index.js +31 -5
  118. package/services/chain-service/types.d.ts +20 -0
  119. package/services/chain-service/utils/index.d.ts +4 -0
  120. package/services/chain-service/utils/index.js +50 -4
  121. package/services/chain-service/utils/patch.js +1 -1
  122. package/services/event-service/index.d.ts +3 -0
  123. package/services/event-service/index.js +4 -0
  124. package/services/event-service/types.d.ts +3 -0
  125. package/services/fee-service/service.js +8 -3
  126. package/services/hiro-service/index.d.ts +17 -0
  127. package/services/hiro-service/index.js +88 -0
  128. package/services/hiro-service/utils/index.d.ts +6 -0
  129. package/services/hiro-service/utils/index.js +72 -0
  130. package/services/history-service/bitcoin-history.d.ts +4 -0
  131. package/services/history-service/bitcoin-history.js +52 -0
  132. package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
  133. package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  134. package/services/history-service/index.d.ts +1 -0
  135. package/services/history-service/index.js +42 -4
  136. package/services/keyring-service/context/handlers/Derive.js +2 -2
  137. package/services/keyring-service/context/handlers/Migration.js +2 -2
  138. package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  139. package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
  140. package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
  141. package/services/migration-service/scripts/index.js +3 -1
  142. package/services/request-service/handler/BitcoinRequestHandler.d.ts +23 -0
  143. package/services/request-service/handler/BitcoinRequestHandler.js +427 -0
  144. package/services/request-service/index.d.ts +9 -2
  145. package/services/request-service/index.js +25 -3
  146. package/services/rune-service/index.d.ts +17 -0
  147. package/services/rune-service/index.js +97 -0
  148. package/services/transaction-service/helpers/index.d.ts +3 -1
  149. package/services/transaction-service/helpers/index.js +5 -0
  150. package/services/transaction-service/index.d.ts +3 -5
  151. package/services/transaction-service/index.js +135 -16
  152. package/services/transaction-service/types.d.ts +12 -2
  153. package/services/transaction-service/utils.js +7 -4
  154. package/strategy/api-request-strategy/context/base.d.ts +15 -0
  155. package/strategy/api-request-strategy/context/base.js +24 -0
  156. package/strategy/api-request-strategy/index.d.ts +15 -0
  157. package/strategy/api-request-strategy/index.js +83 -0
  158. package/strategy/api-request-strategy/types.d.ts +22 -0
  159. package/strategy/api-request-strategy/types.js +1 -0
  160. package/strategy/api-request-strategy/utils/index.d.ts +2 -0
  161. package/strategy/api-request-strategy/utils/index.js +23 -0
  162. package/types/account/info/keyring.d.ts +1 -1
  163. package/types/account/info/keyring.js +1 -1
  164. package/types/balance/index.d.ts +4 -1
  165. package/types/balance/transfer.d.ts +17 -0
  166. package/types/bitcoin.d.ts +93 -0
  167. package/types/bitcoin.js +17 -0
  168. package/types/fee/base.d.ts +4 -1
  169. package/types/fee/bitcoin.d.ts +18 -0
  170. package/types/fee/bitcoin.js +1 -0
  171. package/types/fee/index.d.ts +1 -0
  172. package/types/fee/index.js +2 -1
  173. package/types/fee/subscription.d.ts +4 -3
  174. package/types/index.d.ts +1 -0
  175. package/types/index.js +1 -0
  176. package/utils/account/analyze.js +4 -4
  177. package/utils/account/common.d.ts +7 -8
  178. package/utils/account/common.js +16 -6
  179. package/utils/account/derive/info/solo.js +70 -21
  180. package/utils/account/derive/info/unified.js +2 -0
  181. package/utils/account/derive/validate.d.ts +1 -0
  182. package/utils/account/derive/validate.js +68 -1
  183. package/utils/account/transform.d.ts +1 -1
  184. package/utils/account/transform.js +11 -5
  185. package/utils/bitcoin/common.d.ts +22 -0
  186. package/utils/bitcoin/common.js +88 -0
  187. package/utils/bitcoin/fee.d.ts +2 -0
  188. package/utils/bitcoin/fee.js +14 -0
  189. package/utils/bitcoin/index.d.ts +3 -0
  190. package/utils/bitcoin/index.js +6 -0
  191. package/utils/bitcoin/utxo-management.d.ts +33 -0
  192. package/utils/bitcoin/utxo-management.js +266 -0
  193. package/utils/fee/transfer.d.ts +3 -1
  194. package/utils/fee/transfer.js +47 -1
  195. package/utils/index.d.ts +1 -0
  196. package/utils/index.js +6 -3
@@ -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 {};
@@ -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
+ // ---------------
@@ -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 {};
@@ -3,3 +3,4 @@ export * from './evm';
3
3
  export * from './option';
4
4
  export * from './subscription';
5
5
  export * from './substrate';
6
+ export * from './bitcoin';
@@ -5,4 +5,5 @@ export * from "./base.js";
5
5
  export * from "./evm.js";
6
6
  export * from "./option.js";
7
7
  export * from "./subscription.js";
8
- export * from "./substrate.js";
8
+ export * from "./substrate.js";
9
+ export * from "./bitcoin.js";
@@ -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
@@ -23,3 +23,4 @@ export * from './swap';
23
23
  export * from './transaction';
24
24
  export * from './yield';
25
25
  export * from './setting';
26
+ export * from './bitcoin';
package/types/index.js CHANGED
@@ -16,4 +16,5 @@ export * from "./swap/index.js";
16
16
  export * from "./transaction/index.js";
17
17
  export * from "./yield/index.js";
18
18
  export * from "./setting.js";
19
+ export * from "./bitcoin.js";
19
20
  export {};
@@ -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 { _chainInfoToChainType, _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
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 === currentChainType);
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 === currentChainType);
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
- interface AddressesByChainType {
10
- [ChainType.SUBSTRATE]: string[];
11
- [ChainType.EVM]: string[];
12
- [ChainType.BITCOIN]: string[];
13
- [ChainType.TON]: string[];
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[]): AddressesByChainType;
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;
@@ -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
- export function getAddressesByChainType(addresses, chainTypes) {
56
- const addressByChainTypeMap = getAddressesByChainTypeMap(addresses);
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
- addressByChainType.bitcoin.push(address);
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 {
@@ -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
- if (type === 'ethereum') {
18
- return `m/44'/60'/0'/0/${first}/${secondIndex}`;
19
- } else if (type === 'ton') {
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
- if (type === 'ethereum') {
26
- return `m/44'/60'/0'/0/${first}`;
27
- } else if (type === 'ton') {
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 validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : type === 'cardano' ? validateCardanoDerivationPath : () => undefined;
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 validateTypeFunc = type === 'ethereum' ? validateEvmDerivationPath : type === 'ton' ? validateTonDerivationPath : type === 'cardano' ? validateCardanoDerivationPath : () => undefined;
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
@@ -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[]>;