@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.
Files changed (219) hide show
  1. package/background/KoniTypes.d.ts +134 -5
  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/background/types.d.ts +1 -1
  6. package/cjs/background/KoniTypes.js +20 -1
  7. package/cjs/background/errors/BitcoinProviderError.js +54 -0
  8. package/cjs/constants/bitcoin.js +22 -0
  9. package/cjs/constants/index.js +16 -1
  10. package/cjs/core/logic-validation/recipientAddress.js +9 -0
  11. package/cjs/core/logic-validation/request.js +316 -3
  12. package/cjs/core/logic-validation/transfer.js +25 -5
  13. package/cjs/core/types.js +1 -0
  14. package/cjs/core/utils.js +15 -1
  15. package/cjs/koni/background/handlers/Extension.js +477 -93
  16. package/cjs/koni/background/handlers/State.js +249 -16
  17. package/cjs/koni/background/handlers/Tabs.js +119 -6
  18. package/cjs/packageInfo.js +1 -1
  19. package/cjs/page/bitcoin/index.js +67 -0
  20. package/cjs/page/index.js +5 -0
  21. package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
  22. package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
  23. package/cjs/services/balance-service/index.js +32 -4
  24. package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
  25. package/cjs/services/balance-service/transfer/token.js +2 -0
  26. package/cjs/services/base/types.js +2 -0
  27. package/cjs/services/buy-service/index.js +17 -2
  28. package/cjs/services/chain-service/constants.js +14 -3
  29. package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
  30. package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
  31. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
  32. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
  33. package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
  34. package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
  35. package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  36. package/cjs/services/chain-service/index.js +27 -3
  37. package/cjs/services/chain-service/utils/index.js +57 -4
  38. package/cjs/services/chain-service/utils/patch.js +1 -1
  39. package/cjs/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  40. package/cjs/services/event-service/index.js +4 -0
  41. package/cjs/services/fee-service/service.js +8 -3
  42. package/cjs/services/hiro-service/index.js +96 -0
  43. package/cjs/services/hiro-service/utils/index.js +85 -0
  44. package/cjs/services/history-service/bitcoin-history.js +58 -0
  45. package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  46. package/cjs/services/history-service/index.js +41 -3
  47. package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
  48. package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
  49. package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  50. package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
  51. package/cjs/services/migration-service/scripts/index.js +3 -1
  52. package/cjs/services/request-service/handler/AuthRequestHandler.js +18 -0
  53. package/cjs/services/request-service/handler/BitcoinRequestHandler.js +427 -0
  54. package/cjs/services/request-service/index.js +29 -3
  55. package/cjs/services/rune-service/index.js +105 -0
  56. package/cjs/services/transaction-service/helpers/index.js +7 -1
  57. package/cjs/services/transaction-service/index.js +206 -16
  58. package/cjs/services/transaction-service/utils.js +6 -3
  59. package/cjs/strategy/api-request-strategy/context/base.js +31 -0
  60. package/cjs/strategy/api-request-strategy/index.js +90 -0
  61. package/cjs/strategy/api-request-strategy/types.js +1 -0
  62. package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
  63. package/cjs/types/account/info/keyring.js +1 -1
  64. package/cjs/types/bitcoin.js +24 -0
  65. package/cjs/types/fee/bitcoin.js +1 -0
  66. package/cjs/types/fee/index.js +11 -0
  67. package/cjs/types/index.js +11 -0
  68. package/cjs/utils/account/analyze.js +3 -3
  69. package/cjs/utils/account/common.js +16 -6
  70. package/cjs/utils/account/derive/info/solo.js +68 -19
  71. package/cjs/utils/account/derive/info/unified.js +2 -0
  72. package/cjs/utils/account/derive/validate.js +70 -2
  73. package/cjs/utils/account/transform.js +11 -5
  74. package/cjs/utils/auth.js +2 -1
  75. package/cjs/utils/bitcoin/common.js +98 -0
  76. package/cjs/utils/bitcoin/fee.js +21 -0
  77. package/cjs/utils/bitcoin/index.js +38 -0
  78. package/cjs/utils/bitcoin/utxo-management.js +281 -0
  79. package/cjs/utils/fee/transfer.js +48 -0
  80. package/cjs/utils/index.js +15 -1
  81. package/constants/bitcoin.d.ts +3 -0
  82. package/constants/bitcoin.js +13 -0
  83. package/constants/index.d.ts +2 -0
  84. package/constants/index.js +3 -1
  85. package/core/logic-validation/recipientAddress.js +10 -1
  86. package/core/logic-validation/request.d.ts +6 -2
  87. package/core/logic-validation/request.js +309 -3
  88. package/core/logic-validation/transfer.d.ts +2 -2
  89. package/core/logic-validation/transfer.js +27 -7
  90. package/core/types.d.ts +1 -0
  91. package/core/types.js +1 -0
  92. package/core/utils.d.ts +1 -0
  93. package/core/utils.js +15 -2
  94. package/koni/background/handlers/Extension.d.ts +5 -0
  95. package/koni/background/handlers/Extension.js +387 -9
  96. package/koni/background/handlers/State.d.ts +10 -3
  97. package/koni/background/handlers/State.js +240 -15
  98. package/koni/background/handlers/Tabs.d.ts +7 -2
  99. package/koni/background/handlers/Tabs.js +119 -9
  100. package/package.json +149 -8
  101. package/packageInfo.js +1 -1
  102. package/page/bitcoin/index.d.ts +17 -0
  103. package/page/bitcoin/index.js +60 -0
  104. package/page/index.d.ts +2 -1
  105. package/page/index.js +4 -0
  106. package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
  107. package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
  108. package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
  109. package/services/balance-service/helpers/subscribe/index.js +20 -8
  110. package/services/balance-service/index.d.ts +2 -0
  111. package/services/balance-service/index.js +32 -4
  112. package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
  113. package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
  114. package/services/balance-service/transfer/cardano-transfer.d.ts +2 -0
  115. package/services/balance-service/transfer/token.js +2 -0
  116. package/services/base/types.d.ts +2 -0
  117. package/services/base/types.js +2 -0
  118. package/services/buy-service/index.js +17 -2
  119. package/services/chain-service/constants.d.ts +6 -0
  120. package/services/chain-service/constants.js +8 -2
  121. package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
  122. package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
  123. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
  124. package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
  125. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
  126. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
  127. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
  128. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
  129. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
  130. package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
  131. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
  132. package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
  133. package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
  134. package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
  135. package/services/chain-service/index.d.ts +3 -0
  136. package/services/chain-service/index.js +31 -5
  137. package/services/chain-service/types.d.ts +20 -0
  138. package/services/chain-service/utils/index.d.ts +4 -0
  139. package/services/chain-service/utils/index.js +50 -4
  140. package/services/chain-service/utils/patch.js +1 -1
  141. package/services/earning-service/handlers/native-staking/para-chain.js +27 -5
  142. package/services/event-service/index.d.ts +3 -0
  143. package/services/event-service/index.js +4 -0
  144. package/services/event-service/types.d.ts +3 -0
  145. package/services/fee-service/service.js +8 -3
  146. package/services/hiro-service/index.d.ts +17 -0
  147. package/services/hiro-service/index.js +88 -0
  148. package/services/hiro-service/utils/index.d.ts +6 -0
  149. package/services/hiro-service/utils/index.js +72 -0
  150. package/services/history-service/bitcoin-history.d.ts +4 -0
  151. package/services/history-service/bitcoin-history.js +52 -0
  152. package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
  153. package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
  154. package/services/history-service/index.d.ts +1 -0
  155. package/services/history-service/index.js +42 -4
  156. package/services/keyring-service/context/handlers/Derive.js +2 -2
  157. package/services/keyring-service/context/handlers/Migration.js +2 -2
  158. package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
  159. package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
  160. package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
  161. package/services/migration-service/scripts/index.js +3 -1
  162. package/services/request-service/handler/AuthRequestHandler.js +19 -1
  163. package/services/request-service/handler/BitcoinRequestHandler.d.ts +22 -0
  164. package/services/request-service/handler/BitcoinRequestHandler.js +414 -0
  165. package/services/request-service/index.d.ts +8 -2
  166. package/services/request-service/index.js +25 -3
  167. package/services/rune-service/index.d.ts +17 -0
  168. package/services/rune-service/index.js +97 -0
  169. package/services/transaction-service/helpers/index.d.ts +3 -1
  170. package/services/transaction-service/helpers/index.js +5 -0
  171. package/services/transaction-service/index.d.ts +4 -5
  172. package/services/transaction-service/index.js +205 -17
  173. package/services/transaction-service/types.d.ts +13 -2
  174. package/services/transaction-service/utils.js +7 -4
  175. package/strategy/api-request-strategy/context/base.d.ts +15 -0
  176. package/strategy/api-request-strategy/context/base.js +24 -0
  177. package/strategy/api-request-strategy/index.d.ts +15 -0
  178. package/strategy/api-request-strategy/index.js +83 -0
  179. package/strategy/api-request-strategy/types.d.ts +22 -0
  180. package/strategy/api-request-strategy/types.js +1 -0
  181. package/strategy/api-request-strategy/utils/index.d.ts +2 -0
  182. package/strategy/api-request-strategy/utils/index.js +23 -0
  183. package/types/account/info/keyring.d.ts +1 -1
  184. package/types/account/info/keyring.js +1 -1
  185. package/types/balance/index.d.ts +4 -1
  186. package/types/balance/transfer.d.ts +19 -0
  187. package/types/bitcoin.d.ts +93 -0
  188. package/types/bitcoin.js +17 -0
  189. package/types/buy.d.ts +1 -1
  190. package/types/fee/base.d.ts +4 -1
  191. package/types/fee/bitcoin.d.ts +18 -0
  192. package/types/fee/bitcoin.js +1 -0
  193. package/types/fee/index.d.ts +1 -0
  194. package/types/fee/index.js +2 -1
  195. package/types/fee/subscription.d.ts +4 -3
  196. package/types/index.d.ts +1 -0
  197. package/types/index.js +1 -0
  198. package/utils/account/analyze.js +4 -4
  199. package/utils/account/common.d.ts +7 -8
  200. package/utils/account/common.js +16 -6
  201. package/utils/account/derive/info/solo.js +70 -21
  202. package/utils/account/derive/info/unified.js +2 -0
  203. package/utils/account/derive/validate.d.ts +1 -0
  204. package/utils/account/derive/validate.js +68 -1
  205. package/utils/account/transform.d.ts +1 -1
  206. package/utils/account/transform.js +11 -5
  207. package/utils/auth.js +3 -2
  208. package/utils/bitcoin/common.d.ts +22 -0
  209. package/utils/bitcoin/common.js +88 -0
  210. package/utils/bitcoin/fee.d.ts +2 -0
  211. package/utils/bitcoin/fee.js +14 -0
  212. package/utils/bitcoin/index.d.ts +3 -0
  213. package/utils/bitcoin/index.js +6 -0
  214. package/utils/bitcoin/utxo-management.d.ts +33 -0
  215. package/utils/bitcoin/utxo-management.js +266 -0
  216. package/utils/fee/transfer.d.ts +3 -1
  217. package/utils/fee/transfer.js +47 -1
  218. package/utils/index.d.ts +1 -0
  219. package/utils/index.js +6 -3
@@ -30,6 +30,7 @@ var _relayChain = require("@subwallet/extension-base/koni/api/staking/bonding/re
30
30
  var _utils3 = require("@subwallet/extension-base/koni/api/yield/helper/utils");
31
31
  var _consts = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/cardano/consts");
32
32
  var _utils4 = require("@subwallet/extension-base/services/balance-service/helpers/subscribe/ton/utils");
33
+ var _bitcoinTransfer = require("@subwallet/extension-base/services/balance-service/transfer/bitcoin-transfer");
33
34
  var _cardanoTransfer = require("@subwallet/extension-base/services/balance-service/transfer/cardano-transfer");
34
35
  var _smartContract = require("@subwallet/extension-base/services/balance-service/transfer/smart-contract");
35
36
  var _token = require("@subwallet/extension-base/services/balance-service/transfer/token");
@@ -56,15 +57,20 @@ var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTrans
56
57
  var _getId = require("@subwallet/extension-base/utils/getId");
57
58
  var _keyring = require("@subwallet/keyring");
58
59
  var _types4 = require("@subwallet/keyring/types");
60
+ var _utils9 = require("@subwallet/keyring/utils");
61
+ var _validate = require("@subwallet/keyring/utils/address/validate");
59
62
  var _uiKeyring = require("@subwallet/ui-keyring");
60
- var _utils9 = require("@walletconnect/utils");
63
+ var _utils10 = require("@walletconnect/utils");
61
64
  var _bignumber = _interopRequireDefault(require("bignumber.js"));
65
+ var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
62
66
  var _i18next = require("i18next");
63
67
  var _rxjs = require("rxjs");
64
68
  var _types5 = require("@polkadot/types");
65
69
  var _util = require("@polkadot/util");
66
70
  var _utilCrypto = require("@polkadot/util-crypto");
67
- var _utils10 = require("../utils");
71
+ var _utils11 = require("../utils");
72
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
73
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
68
74
  // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
69
75
  // SPDX-License-Identifier: Apache-2.0
70
76
 
@@ -585,7 +591,8 @@ class KoniExtension {
585
591
  evm: _types4.EthereumKeypairTypes,
586
592
  substrate: _types4.SubstrateKeypairTypes,
587
593
  ton: _types4.TonKeypairTypes,
588
- cardano: _types4.CardanoKeypairTypes
594
+ cardano: _types4.CardanoKeypairTypes,
595
+ bitcoin: _types4.BitcoinKeypairTypes
589
596
  };
590
597
  return !!accountAuthTypes && accountAuthTypes.some(authType => {
591
598
  var _validTypes$authType;
@@ -700,7 +707,8 @@ class KoniExtension {
700
707
  substrate: 'substrateInfo',
701
708
  evm: 'evmInfo',
702
709
  cardano: 'cardanoInfo',
703
- ton: 'tonInfo'
710
+ ton: 'tonInfo',
711
+ bitcoin: 'bitcoinInfo'
704
712
  };
705
713
  const typeInfoKey = typeInfoMap[authSwitchNetworkType];
706
714
  if (!typeInfoKey || !chainInfo[typeInfoKey]) {
@@ -1292,6 +1300,7 @@ class KoniExtension {
1292
1300
  decimals: (0, _utils6._getAssetDecimals)(transferTokenInfo)
1293
1301
  };
1294
1302
  let transaction;
1303
+ let overrideFeeCustom;
1295
1304
  const transferTokenAvailable = await this.getAddressTransferableBalance({
1296
1305
  address: from,
1297
1306
  networkKey: chain,
@@ -1363,6 +1372,39 @@ class KoniExtension {
1363
1372
  cardanoApi,
1364
1373
  nativeTokenInfo
1365
1374
  });
1375
+ } else if ((0, _validate.isBitcoinAddress)(from) && (0, _validate.isBitcoinAddress)(to) && (0, _utils6._isTokenTransferredByBitcoin)(transferTokenInfo)) {
1376
+ // Note: Currently supports transferring only the native token, Bitcoin.
1377
+ chainType = _KoniTypes.ChainType.BITCOIN;
1378
+ const chainInfo = this.#koniState.getChainInfo(chain);
1379
+ const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
1380
+ const txVal = transferAll ? transferTokenAvailable.value : value || '0';
1381
+ const bitcoinApi = this.#koniState.getBitcoinApi(chain);
1382
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'bitcoin');
1383
+ let calculatedBitcoinFeeRate;
1384
+ [transaction, transferAmount.value, calculatedBitcoinFeeRate] = await (0, _bitcoinTransfer.createBitcoinTransaction)({
1385
+ bitcoinApi,
1386
+ chain,
1387
+ from,
1388
+ feeInfo,
1389
+ to,
1390
+ transferAll: !!transferAll,
1391
+ value: txVal,
1392
+ network: network
1393
+ });
1394
+ if (calculatedBitcoinFeeRate) {
1395
+ const feeRate = parseFloat(calculatedBitcoinFeeRate);
1396
+ if (!isNaN(feeRate)) {
1397
+ overrideFeeCustom = {
1398
+ feeRate
1399
+ };
1400
+ }
1401
+ }
1402
+
1403
+ // TODO: This is a hotfix until transferMax for Bitcoin is supported.
1404
+ if (transferAll) {
1405
+ inputData.value = transferAmount.value;
1406
+ }
1407
+ console.log('PSPT transaction', transaction.toHex());
1366
1408
  } else {
1367
1409
  const substrateApi = this.#koniState.getSubstrateApi(chain);
1368
1410
  [transaction, transferAmount.value] = await (0, _token.createSubstrateExtrinsic)({
@@ -1453,8 +1495,8 @@ class KoniExtension {
1453
1495
  warnings,
1454
1496
  address: from,
1455
1497
  chain,
1456
- feeCustom,
1457
- feeOption,
1498
+ feeCustom: overrideFeeCustom || feeCustom,
1499
+ feeOption: overrideFeeCustom ? 'custom' : feeOption,
1458
1500
  tokenPayFeeSlug,
1459
1501
  chainType,
1460
1502
  transferNativeAmount,
@@ -1674,6 +1716,192 @@ class KoniExtension {
1674
1716
  eventsHandler: eventsHandler
1675
1717
  });
1676
1718
  }
1719
+ async makeBitcoinDappTransferConfirmation(inputData) {
1720
+ const {
1721
+ chain,
1722
+ feeCustom,
1723
+ feeOption,
1724
+ from,
1725
+ id,
1726
+ to,
1727
+ tokenSlug,
1728
+ transferAll,
1729
+ value
1730
+ } = inputData;
1731
+ const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(tokenSlug);
1732
+ const errors = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, to, value, transferAll);
1733
+ const warnings = [];
1734
+ const chainInfo = this.#koniState.getChainInfo(chain);
1735
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(chain);
1736
+ const nativeTokenSlug = nativeTokenInfo.slug;
1737
+ const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1738
+ let chainType = _KoniTypes.ChainType.BITCOIN;
1739
+ const tokenBaseAmount = {
1740
+ value: '0',
1741
+ symbol: transferTokenInfo.symbol,
1742
+ decimals: transferTokenInfo.decimals || 0
1743
+ };
1744
+ const transferAmount = {
1745
+ ...tokenBaseAmount
1746
+ };
1747
+ let transaction;
1748
+ let overrideFeeCustom;
1749
+ let calculatedBitcoinFeeRate;
1750
+
1751
+ // Get native token amount
1752
+ const freeBalance = await this.getAddressTransferableBalance({
1753
+ address: from,
1754
+ networkKey: chain,
1755
+ token: tokenSlug
1756
+ });
1757
+ const txVal = transferAll ? freeBalance.value : value || '0';
1758
+ try {
1759
+ if ((0, _utils6._isChainBitcoinCompatible)(chainInfo)) {
1760
+ chainType = _KoniTypes.ChainType.BITCOIN;
1761
+ const bitcoinApi = this.#koniState.getBitcoinApi(chain); // Get Bitcoin API map
1762
+ const network = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
1763
+ const feeInfo = await this.#koniState.feeService.subscribeChainFee((0, _getId.getId)(), chain, 'bitcoin');
1764
+ [transaction, transferAmount.value, calculatedBitcoinFeeRate] = await (0, _bitcoinTransfer.createBitcoinTransaction)({
1765
+ bitcoinApi,
1766
+ chain,
1767
+ from,
1768
+ feeInfo,
1769
+ to,
1770
+ transferAll: transferAll,
1771
+ value: txVal,
1772
+ network: network
1773
+ });
1774
+ if (calculatedBitcoinFeeRate) {
1775
+ const feeRate = parseFloat(calculatedBitcoinFeeRate);
1776
+ if (!isNaN(feeRate)) {
1777
+ overrideFeeCustom = {
1778
+ feeRate
1779
+ };
1780
+ }
1781
+ }
1782
+ }
1783
+ } catch (e) {
1784
+ const error = e;
1785
+ if (error.message.includes('transfer amount exceeds balance')) {
1786
+ error.message = (0, _i18next.t)('Insufficient balance');
1787
+ }
1788
+ throw error;
1789
+ }
1790
+ const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1791
+ return this.#koniState.transactionService.handleTransactionAfterConfirmation({
1792
+ id,
1793
+ errors,
1794
+ warnings,
1795
+ address: from,
1796
+ chain: chain,
1797
+ feeCustom: overrideFeeCustom || feeCustom,
1798
+ feeOption: overrideFeeCustom ? 'custom' : feeOption,
1799
+ chainType,
1800
+ transferNativeAmount,
1801
+ transaction,
1802
+ data: inputData,
1803
+ extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1804
+ ignoreWarnings: [],
1805
+ isTransferAll: isTransferNativeToken ? transferAll : false,
1806
+ edAsWarning: isTransferNativeToken
1807
+ });
1808
+ }
1809
+ async makePsbtTransferAfterConfirmation(inputData_) {
1810
+ var _txOutput$;
1811
+ const {
1812
+ chain,
1813
+ from,
1814
+ id,
1815
+ psbt,
1816
+ tokenSlug,
1817
+ txInput,
1818
+ txOutput,
1819
+ value
1820
+ } = inputData_;
1821
+ let inputAmount = new _bignumber.default(0);
1822
+ const transferTokenInfo = this.#koniState.chainService.getAssetBySlug(tokenSlug);
1823
+ const totalUtxoInput = txInput.reduce((total, _ref33) => {
1824
+ let {
1825
+ address,
1826
+ amount
1827
+ } = _ref33;
1828
+ if (!address || !amount) {
1829
+ return total;
1830
+ }
1831
+ if ((0, _utils8.isSameAddress)(address, from)) {
1832
+ inputAmount = new _bignumber.default(amount);
1833
+ }
1834
+ return total.plus(new _bignumber.default(amount || 0));
1835
+ }, new _bignumber.default(0));
1836
+ const totalUtxoOutput = txOutput.reduce((total, _ref34) => {
1837
+ let {
1838
+ address,
1839
+ amount
1840
+ } = _ref34;
1841
+ if (!address || !amount) {
1842
+ return total;
1843
+ }
1844
+ return total.plus(new _bignumber.default(amount));
1845
+ }, new _bignumber.default(0));
1846
+ const estimateFeeValue = totalUtxoInput.minus(totalUtxoOutput).toString();
1847
+ const errors = (0, _transfer.validateTransferRequest)(transferTokenInfo, from, ((_txOutput$ = txOutput[0]) === null || _txOutput$ === void 0 ? void 0 : _txOutput$.address) || '', value, false);
1848
+ const warnings = [];
1849
+ const chainInfo = this.#koniState.getChainInfo(chain);
1850
+ const {
1851
+ decimals,
1852
+ symbol
1853
+ } = (0, _utils6._getChainNativeTokenBasicInfo)(chainInfo);
1854
+ const estimateFee = {
1855
+ symbol,
1856
+ decimals,
1857
+ value: estimateFeeValue,
1858
+ tooHigh: false
1859
+ };
1860
+ const nativeTokenInfo = this.#koniState.getNativeTokenInfo(chain);
1861
+ const nativeTokenSlug = nativeTokenInfo.slug;
1862
+ const isTransferNativeToken = nativeTokenSlug === tokenSlug;
1863
+ const chainType = _KoniTypes.ChainType.BITCOIN;
1864
+ const bitcoinNetwork = chainInfo.isTestnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
1865
+ const psbtGenerate = bitcoin.Psbt.fromHex(psbt, {
1866
+ network: bitcoinNetwork
1867
+ });
1868
+ const tokenBaseAmount = {
1869
+ value: inputData_.value,
1870
+ symbol: transferTokenInfo.symbol,
1871
+ decimals: transferTokenInfo.decimals || 0
1872
+ };
1873
+ const transferAmount = {
1874
+ ...tokenBaseAmount
1875
+ };
1876
+
1877
+ // Get native token amount
1878
+ const freeBalance = await this.getAddressTransferableBalance({
1879
+ address: from,
1880
+ networkKey: chain,
1881
+ token: tokenSlug
1882
+ });
1883
+ if (new _bignumber.default(freeBalance.value).lt(inputAmount)) {
1884
+ throw new Error((0, _i18next.t)('Insufficient balance'));
1885
+ }
1886
+ const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
1887
+ return this.#koniState.transactionService.handleTransactionAfterConfirmation({
1888
+ id,
1889
+ errors,
1890
+ warnings,
1891
+ address: from,
1892
+ chain: chain,
1893
+ estimateFee,
1894
+ chainType,
1895
+ transferNativeAmount,
1896
+ transaction: psbtGenerate,
1897
+ data: inputData_,
1898
+ extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
1899
+ ignoreWarnings: [],
1900
+ isTransferAll: false,
1901
+ edAsWarning: isTransferNativeToken,
1902
+ skipFeeRecalculation: true
1903
+ });
1904
+ }
1677
1905
  async getTokensCanPayFee(request) {
1678
1906
  var _tokensHasBalanceInfo;
1679
1907
  const {
@@ -1793,28 +2021,28 @@ class KoniExtension {
1793
2021
  disableChain(networkKey) {
1794
2022
  return this.#koniState.disableChain(networkKey);
1795
2023
  }
1796
- async enableChain(_ref33) {
2024
+ async enableChain(_ref35) {
1797
2025
  let {
1798
2026
  chainSlug,
1799
2027
  enableTokens
1800
- } = _ref33;
2028
+ } = _ref35;
1801
2029
  return await this.#koniState.enableChain(chainSlug, enableTokens);
1802
2030
  }
1803
- async enableChainWithPriorityAssets(_ref34) {
2031
+ async enableChainWithPriorityAssets(_ref36) {
1804
2032
  let {
1805
2033
  chainSlug,
1806
2034
  enableTokens
1807
- } = _ref34;
2035
+ } = _ref36;
1808
2036
  return await this.#koniState.enableChainWithPriorityAssets(chainSlug, enableTokens);
1809
2037
  }
1810
2038
  async reconnectChain(chainSlug) {
1811
2039
  return this.#koniState.chainService.reconnectChain(chainSlug);
1812
2040
  }
1813
- async validateNetwork(_ref35) {
2041
+ async validateNetwork(_ref37) {
1814
2042
  let {
1815
2043
  existedChainSlug,
1816
2044
  provider
1817
- } = _ref35;
2045
+ } = _ref37;
1818
2046
  return await this.#koniState.validateCustomChain(provider, existedChainSlug);
1819
2047
  }
1820
2048
  resetDefaultNetwork() {
@@ -1886,13 +2114,13 @@ class KoniExtension {
1886
2114
  async validateCustomAsset(data) {
1887
2115
  return await this.#koniState.validateCustomAsset(data);
1888
2116
  }
1889
- async getAddressTransferableBalance(_ref36) {
2117
+ async getAddressTransferableBalance(_ref38) {
1890
2118
  let {
1891
2119
  address,
1892
2120
  extrinsicType,
1893
2121
  networkKey,
1894
2122
  token
1895
- } = _ref36;
2123
+ } = _ref38;
1896
2124
  if (token && _constants2._MANTA_ZK_CHAIN_GROUP.includes(networkKey)) {
1897
2125
  const tokenInfo = this.#koniState.chainService.getAssetBySlug(token);
1898
2126
  if (tokenInfo.symbol.startsWith(_constants2._ZK_ASSET_PREFIX)) {
@@ -1901,13 +2129,13 @@ class KoniExtension {
1901
2129
  }
1902
2130
  return await this.#koniState.balanceService.getTransferableBalance(address, networkKey, token, extrinsicType);
1903
2131
  }
1904
- async getAddressTotalBalance(_ref37) {
2132
+ async getAddressTotalBalance(_ref39) {
1905
2133
  let {
1906
2134
  address,
1907
2135
  extrinsicType,
1908
2136
  networkKey,
1909
2137
  token
1910
- } = _ref37;
2138
+ } = _ref39;
1911
2139
  return await this.#koniState.balanceService.getTotalBalance(address, networkKey, token, extrinsicType);
1912
2140
  }
1913
2141
  async subscribeMaxTransferable(request, id, port) {
@@ -1917,6 +2145,7 @@ class KoniExtension {
1917
2145
  destChain: _destChain,
1918
2146
  feeCustom,
1919
2147
  feeOption,
2148
+ to,
1920
2149
  token,
1921
2150
  tokenPayFeeSlug,
1922
2151
  value
@@ -1939,6 +2168,7 @@ class KoniExtension {
1939
2168
  }
1940
2169
  const _request = {
1941
2170
  address: address,
2171
+ to: to,
1942
2172
  value,
1943
2173
  // todo: lazy subscribe to improve performance
1944
2174
  cardanoApi: this.#koniState.chainService.getCardanoApi(chain),
@@ -1951,6 +2181,7 @@ class KoniExtension {
1951
2181
  srcToken,
1952
2182
  substrateApi: this.#koniState.chainService.getSubstrateApi(chain),
1953
2183
  tonApi: this.#koniState.chainService.getTonApi(chain),
2184
+ bitcoinApi: this.#koniState.chainService.getBitcoinApi(chain),
1954
2185
  isTransferLocalTokenAndPayThatTokenAsFee,
1955
2186
  isTransferNativeTokenAndPayLocalTokenAsFee,
1956
2187
  nativeToken
@@ -1959,11 +2190,11 @@ class KoniExtension {
1959
2190
  freeBalance: freeBalanceSubject,
1960
2191
  fee: feeSubject
1961
2192
  }).subscribe({
1962
- next: _ref38 => {
2193
+ next: _ref40 => {
1963
2194
  let {
1964
2195
  fee,
1965
2196
  freeBalance
1966
- } = _ref38;
2197
+ } = _ref40;
1967
2198
  (0, _utils8.calculateMaxTransferable)(id, _request, freeBalance, fee).then(cb).catch(console.error);
1968
2199
  }
1969
2200
  });
@@ -1997,13 +2228,144 @@ class KoniExtension {
1997
2228
  });
1998
2229
  return (0, _utils8.calculateMaxTransferable)(id, _request, freeBalance, fee);
1999
2230
  }
2000
- async subscribeAddressTransferableBalance(_ref39, id, port) {
2231
+ async subscribeTransferableWhenConfirmation(_ref41, id, port) {
2232
+ let {
2233
+ address,
2234
+ chain,
2235
+ feeCustom,
2236
+ feeOption: _feeOptions,
2237
+ to,
2238
+ token,
2239
+ value
2240
+ } = _ref41;
2241
+ const cb = (0, _subscriptions.createSubscription)(id, port);
2242
+ const freeBalanceSubject = new _rxjs.Subject();
2243
+ const feeSubject = new _rxjs.Subject();
2244
+ const feeType = 'bitcoin';
2245
+ let error;
2246
+ const convertData = async (freeBalance, fee, feeOption, feeCustom) => {
2247
+ let estimatedFee = '0';
2248
+ let feeOptions = null;
2249
+ const amount = parseInt(value || '0');
2250
+ const neededUtxos = [];
2251
+ let sum = new _bignumber.default(0);
2252
+ let sizeInfo = null;
2253
+ try {
2254
+ const _fee = fee;
2255
+ const _feeCustom = feeCustom;
2256
+ const combineFee = (0, _utils8.combineBitcoinFee)(_fee, _feeOptions, _feeCustom);
2257
+ const bitcoinApi = this.#koniState.chainService.getBitcoinApi(chain);
2258
+ let utxos = await (0, _utils8.getTransferableBitcoinUtxos)(bitcoinApi, address);
2259
+ const recipients = [address, to || address];
2260
+ utxos = utxos.sort((a, b) => b.value - a.value);
2261
+ const filteredUtxos = (0, _utils8.filterUneconomicalUtxos)({
2262
+ utxos,
2263
+ feeRate: combineFee.feeRate,
2264
+ recipients,
2265
+ sender: address
2266
+ });
2267
+ for (const utxo of filteredUtxos) {
2268
+ sizeInfo = (0, _utils8.getSizeInfo)({
2269
+ inputLength: neededUtxos.length,
2270
+ sender: address,
2271
+ recipients
2272
+ });
2273
+ const currentValue = new _bignumber.default(amount).plus(Math.ceil(sizeInfo.txVBytes * combineFee.feeRate));
2274
+ if (sum.gte(currentValue)) {
2275
+ break;
2276
+ }
2277
+ sum = sum.plus(utxo.value);
2278
+ neededUtxos.push(utxo);
2279
+ }
2280
+
2281
+ // re calculate
2282
+ sizeInfo = (0, _utils8.getSizeInfo)({
2283
+ inputLength: neededUtxos.length,
2284
+ sender: address,
2285
+ recipients
2286
+ });
2287
+ if (!sizeInfo) {
2288
+ sizeInfo = (0, _utils8.getSizeInfo)({
2289
+ inputLength: utxos.length || 1,
2290
+ sender: address,
2291
+ recipients
2292
+ });
2293
+ }
2294
+ estimatedFee = Math.ceil(sizeInfo.txVBytes * combineFee.feeRate).toString();
2295
+ const amountLeft = sum.minus(amount).minus(new _bignumber.default(estimatedFee));
2296
+ if (amountLeft.lte(0)) {
2297
+ error = 'Insufficient balance';
2298
+ } else {
2299
+ const senderAddressInfo = (0, _utils9.getBitcoinAddressInfo)(address);
2300
+ const dustLimit = _constants.BTC_DUST_AMOUNT[senderAddressInfo.type] || 546;
2301
+ if (amountLeft.lte(dustLimit)) {
2302
+ sizeInfo = (0, _utils8.getSizeInfo)({
2303
+ inputLength: neededUtxos.length,
2304
+ sender: address,
2305
+ recipients: [to || address]
2306
+ });
2307
+ estimatedFee = sum.minus(amount).toString();
2308
+ }
2309
+ }
2310
+ feeOptions = {
2311
+ ...fee,
2312
+ vSize: sizeInfo.txVBytes,
2313
+ estimatedFee
2314
+ };
2315
+ } catch (e) {
2316
+ feeOptions = {
2317
+ ...fee,
2318
+ estimatedFee,
2319
+ vSize: 0
2320
+ };
2321
+ error = e.message || e;
2322
+ console.warn('Unable to estimate fee', e);
2323
+ }
2324
+ return {
2325
+ feeOptions: feeOptions,
2326
+ feeType,
2327
+ error,
2328
+ id
2329
+ };
2330
+ };
2331
+ const subscription = (0, _rxjs.combineLatest)({
2332
+ freeBalance: freeBalanceSubject,
2333
+ fee: feeSubject
2334
+ }).subscribe({
2335
+ next: _ref42 => {
2336
+ let {
2337
+ fee,
2338
+ freeBalance
2339
+ } = _ref42;
2340
+ convertData(freeBalance, fee, _feeOptions, feeCustom).then(cb).catch(console.error);
2341
+ }
2342
+ });
2343
+ const [unsubBalance, freeBalance] = await this.#koniState.balanceService.subscribeBalance(address, chain, token, 'transferable', _KoniTypes.ExtrinsicType.TRANSFER_BALANCE, data => {
2344
+ freeBalanceSubject.next(data); // Must be called after subscription
2345
+ });
2346
+
2347
+ const fee = await this.#koniState.feeService.subscribeChainFee(id, chain, feeType, data => {
2348
+ feeSubject.next(data); // Must be called after subscription
2349
+ });
2350
+
2351
+ const unsub = () => {
2352
+ subscription.unsubscribe();
2353
+ unsubBalance();
2354
+ this.#koniState.feeService.unsubscribeChainFee(id, chain, feeType);
2355
+ };
2356
+ this.createUnsubscriptionHandle(id, unsub);
2357
+ port.onDisconnect.addListener(() => {
2358
+ this.cancelSubscription(id);
2359
+ });
2360
+ return convertData(freeBalance, fee, _feeOptions, feeCustom);
2361
+ }
2362
+ async subscribeAddressTransferableBalance(_ref43, id, port) {
2001
2363
  let {
2002
2364
  address,
2003
2365
  extrinsicType,
2004
2366
  networkKey,
2005
2367
  token
2006
- } = _ref39;
2368
+ } = _ref43;
2007
2369
  const cb = (0, _subscriptions.createSubscription)(id, port);
2008
2370
  const convertData = data => {
2009
2371
  return {
@@ -2054,11 +2416,11 @@ class KoniExtension {
2054
2416
  isSendingSelf
2055
2417
  };
2056
2418
  }
2057
- async enableChains(_ref40) {
2419
+ async enableChains(_ref44) {
2058
2420
  let {
2059
2421
  chainSlugs,
2060
2422
  enableTokens
2061
- } = _ref40;
2423
+ } = _ref44;
2062
2424
  try {
2063
2425
  await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
2064
2426
  chainSlug,
@@ -2151,6 +2513,15 @@ class KoniExtension {
2151
2513
  });
2152
2514
  return this.#koniState.getConfirmationsQueueSubjectCardano().getValue();
2153
2515
  }
2516
+ subscribeConfirmationsBitcoin(id, port) {
2517
+ const cb = (0, _subscriptions.createSubscription)(id, port);
2518
+ const subscription = this.#koniState.getConfirmationsQueueSubjectBitcoin().subscribe(cb);
2519
+ this.createUnsubscriptionHandle(id, subscription.unsubscribe);
2520
+ port.onDisconnect.addListener(() => {
2521
+ this.cancelSubscription(id);
2522
+ });
2523
+ return this.#koniState.getConfirmationsQueueSubjectBitcoin().getValue();
2524
+ }
2154
2525
  async completeConfirmation(request) {
2155
2526
  return await this.#koniState.completeConfirmation(request);
2156
2527
  }
@@ -2160,7 +2531,9 @@ class KoniExtension {
2160
2531
  async completeConfirmationCardano(request) {
2161
2532
  return await this.#koniState.completeConfirmationCardano(request);
2162
2533
  }
2163
-
2534
+ async completeConfirmationBitcoin(request) {
2535
+ return await this.#koniState.completeConfirmationBitcoin(request);
2536
+ }
2164
2537
  /// Sign Qr
2165
2538
 
2166
2539
  getNetworkJsonByChainId(chainId) {
@@ -2191,30 +2564,30 @@ class KoniExtension {
2191
2564
 
2192
2565
  // Parse transaction
2193
2566
 
2194
- parseSubstrateTransaction(_ref41) {
2567
+ parseSubstrateTransaction(_ref45) {
2195
2568
  let {
2196
2569
  data,
2197
2570
  networkKey
2198
- } = _ref41;
2571
+ } = _ref45;
2199
2572
  const apiProps = this.#koniState.getSubstrateApi(networkKey);
2200
2573
  const apiPromise = apiProps.api;
2201
2574
  return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
2202
2575
  }
2203
- async parseEVMRLP(_ref42) {
2576
+ async parseEVMRLP(_ref46) {
2204
2577
  let {
2205
2578
  data
2206
- } = _ref42;
2579
+ } = _ref46;
2207
2580
  return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
2208
2581
  }
2209
2582
 
2210
2583
  // Sign
2211
2584
 
2212
- qrSignSubstrate(_ref43) {
2585
+ qrSignSubstrate(_ref47) {
2213
2586
  let {
2214
2587
  address,
2215
2588
  data,
2216
2589
  networkKey
2217
- } = _ref43;
2590
+ } = _ref47;
2218
2591
  const pair = _uiKeyring.keyring.getPair(address);
2219
2592
  (0, _util.assert)(pair, (0, _i18next.t)('Unable to find account'));
2220
2593
  if (pair.isLocked) {
@@ -2231,13 +2604,13 @@ class KoniExtension {
2231
2604
  signature: signed
2232
2605
  };
2233
2606
  }
2234
- async qrSignEVM(_ref44) {
2607
+ async qrSignEVM(_ref48) {
2235
2608
  let {
2236
2609
  address,
2237
2610
  chainId,
2238
2611
  message,
2239
2612
  type
2240
- } = _ref44;
2613
+ } = _ref48;
2241
2614
  let signed;
2242
2615
  const network = this.getNetworkJsonByChainId(chainId);
2243
2616
  if (!network) {
@@ -2321,11 +2694,11 @@ class KoniExtension {
2321
2694
  });
2322
2695
  return this.#koniState.getNominatorMetadata();
2323
2696
  }
2324
- async getBondingOptions(_ref45) {
2697
+ async getBondingOptions(_ref49) {
2325
2698
  let {
2326
2699
  chain,
2327
2700
  type
2328
- } = _ref45;
2701
+ } = _ref49;
2329
2702
  const apiProps = this.#koniState.getSubstrateApi(chain);
2330
2703
  const chainInfo = this.#koniState.getChainInfo(chain);
2331
2704
  const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
@@ -2515,12 +2888,12 @@ class KoniExtension {
2515
2888
  }
2516
2889
 
2517
2890
  // EVM Transaction
2518
- async parseContractInput(_ref46) {
2891
+ async parseContractInput(_ref50) {
2519
2892
  let {
2520
2893
  chainId,
2521
2894
  contract,
2522
2895
  data
2523
- } = _ref46;
2896
+ } = _ref50;
2524
2897
  const network = this.getNetworkJsonByChainId(chainId);
2525
2898
  return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
2526
2899
  }
@@ -2620,10 +2993,10 @@ class KoniExtension {
2620
2993
 
2621
2994
  // Unlock wallet
2622
2995
 
2623
- keyringUnlock(_ref47) {
2996
+ keyringUnlock(_ref51) {
2624
2997
  let {
2625
2998
  password
2626
- } = _ref47;
2999
+ } = _ref51;
2627
3000
  try {
2628
3001
  _uiKeyring.keyring.unlockKeyring(password);
2629
3002
  // this.#koniState.initMantaPay(password)
@@ -2654,11 +3027,11 @@ class KoniExtension {
2654
3027
 
2655
3028
  // Export mnemonic
2656
3029
 
2657
- keyringExportMnemonic(_ref48) {
3030
+ keyringExportMnemonic(_ref52) {
2658
3031
  let {
2659
3032
  address,
2660
3033
  password
2661
- } = _ref48;
3034
+ } = _ref52;
2662
3035
  const pair = _uiKeyring.keyring.getPair(address);
2663
3036
  const result = pair.exportMnemonic(password);
2664
3037
  return {
@@ -2668,10 +3041,10 @@ class KoniExtension {
2668
3041
 
2669
3042
  // Reset wallet
2670
3043
 
2671
- async resetWallet(_ref49) {
3044
+ async resetWallet(_ref53) {
2672
3045
  let {
2673
3046
  resetAll
2674
- } = _ref49;
3047
+ } = _ref53;
2675
3048
  try {
2676
3049
  await this.#koniState.resetWallet(resetAll);
2677
3050
  return {
@@ -2687,10 +3060,10 @@ class KoniExtension {
2687
3060
  }
2688
3061
 
2689
3062
  // Signing substrate request
2690
- async signingApprovePasswordV2(_ref50) {
3063
+ async signingApprovePasswordV2(_ref54) {
2691
3064
  let {
2692
3065
  id
2693
- } = _ref50;
3066
+ } = _ref54;
2694
3067
  const queued = this.#koniState.getSignRequest(id);
2695
3068
  (0, _util.assert)(queued, (0, _i18next.t)('Unable to proceed. Please try again'));
2696
3069
  const {
@@ -2719,12 +3092,12 @@ class KoniExtension {
2719
3092
  let registry = new _types5.TypeRegistry();
2720
3093
  if (isJsonPayload(payload)) {
2721
3094
  const [, chainInfo] = this.#koniState.findNetworkKeyByGenesisHash(payload.genesisHash);
2722
- const registries = await Promise.all([(0, _utils10.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils10.setupDatabaseRegistry)(chainInfo, payload, this.#koniState), (0, _utils10.setupDappRegistry)(payload, this.#koniState)]);
3095
+ const registries = await Promise.all([(0, _utils11.setupApiRegistry)(chainInfo, this.#koniState), (0, _utils11.setupDatabaseRegistry)(chainInfo, payload, this.#koniState), (0, _utils11.setupDappRegistry)(payload, this.#koniState)]);
2723
3096
  const validRegistries = registries.filter(item => !!(item !== null && item !== void 0 && item.registry));
2724
3097
  if (validRegistries.length === 0) {
2725
3098
  registry.setSignedExtensions(payload.signedExtensions);
2726
3099
  } else {
2727
- registry = (0, _utils10.getSuitableRegistry)(validRegistries, payload);
3100
+ registry = (0, _utils11.getSuitableRegistry)(validRegistries, payload);
2728
3101
  }
2729
3102
  }
2730
3103
  const result = request.sign(registry, pair);
@@ -2849,10 +3222,10 @@ class KoniExtension {
2849
3222
  getSupportedSmartContractTypes() {
2850
3223
  return this.#koniState.getSupportedSmartContractTypes();
2851
3224
  }
2852
- getTransaction(_ref51) {
3225
+ getTransaction(_ref55) {
2853
3226
  let {
2854
3227
  id
2855
- } = _ref51;
3228
+ } = _ref55;
2856
3229
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2857
3230
  const {
2858
3231
  transaction,
@@ -2863,11 +3236,12 @@ class KoniExtension {
2863
3236
  async subscribeTransactions(id, port) {
2864
3237
  const cb = (0, _subscriptions.createSubscription)(id, port);
2865
3238
  function convertRs(rs, processMap) {
2866
- return Object.fromEntries(Object.entries(rs).map(_ref52 => {
2867
- let [key, value] = _ref52;
3239
+ return Object.fromEntries(Object.entries(rs).map(_ref56 => {
3240
+ let [key, value] = _ref56;
2868
3241
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
2869
3242
  const {
2870
3243
  additionalValidator,
3244
+ emitterTransaction,
2871
3245
  eventsHandler,
2872
3246
  step,
2873
3247
  transaction,
@@ -2889,11 +3263,11 @@ class KoniExtension {
2889
3263
  const subscription = (0, _rxjs.combineLatest)({
2890
3264
  transactions: transactionsObservable,
2891
3265
  processMap: processTransactionObservable
2892
- }).subscribe(_ref53 => {
3266
+ }).subscribe(_ref57 => {
2893
3267
  let {
2894
3268
  processMap,
2895
3269
  transactions
2896
- } = _ref53;
3270
+ } = _ref57;
2897
3271
  cb(convertRs(transactions, processMap));
2898
3272
  });
2899
3273
  port.onDisconnect.addListener(() => {
@@ -2914,10 +3288,10 @@ class KoniExtension {
2914
3288
  });
2915
3289
  return notificationSubject.value;
2916
3290
  }
2917
- async reloadCron(_ref54) {
3291
+ async reloadCron(_ref58) {
2918
3292
  let {
2919
3293
  data
2920
- } = _ref54;
3294
+ } = _ref58;
2921
3295
  if (data === 'nft') {
2922
3296
  return await this.#koniState.reloadNft();
2923
3297
  } else if (data === 'staking') {
@@ -2960,10 +3334,10 @@ class KoniExtension {
2960
3334
  }
2961
3335
 
2962
3336
  // Phishing detect
2963
- async passPhishingPage(_ref55) {
3337
+ async passPhishingPage(_ref59) {
2964
3338
  let {
2965
3339
  url
2966
- } = _ref55;
3340
+ } = _ref59;
2967
3341
  return await this.#koniState.approvePassPhishingPage(url);
2968
3342
  }
2969
3343
 
@@ -2984,10 +3358,10 @@ class KoniExtension {
2984
3358
  /// Wallet connect
2985
3359
 
2986
3360
  // Connect
2987
- async connectWalletConnect(_ref56) {
3361
+ async connectWalletConnect(_ref60) {
2988
3362
  let {
2989
3363
  uri
2990
- } = _ref56;
3364
+ } = _ref60;
2991
3365
  await this.#koniState.walletConnectService.connect(uri);
2992
3366
  return true;
2993
3367
  }
@@ -3000,11 +3374,11 @@ class KoniExtension {
3000
3374
  });
3001
3375
  return this.#koniState.requestService.allConnectWCRequests;
3002
3376
  }
3003
- async approveWalletConnectSession(_ref57) {
3377
+ async approveWalletConnectSession(_ref61) {
3004
3378
  let {
3005
3379
  accounts: selectedAccounts,
3006
3380
  id
3007
- } = _ref57;
3381
+ } = _ref61;
3008
3382
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3009
3383
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
3010
3384
  throw new Error('The proposal has been expired');
@@ -3016,22 +3390,22 @@ class KoniExtension {
3016
3390
  const availableNamespaces = {};
3017
3391
  const namespaces = {};
3018
3392
  const chainInfoMap = this.#koniState.getChainInfoMap();
3019
- Object.entries(requiredNamespaces).forEach(_ref58 => {
3020
- let [key, namespace] = _ref58;
3393
+ Object.entries(requiredNamespaces).forEach(_ref62 => {
3394
+ let [key, namespace] = _ref62;
3021
3395
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3022
3396
  if (namespace.chains) {
3023
3397
  const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
3024
3398
  if (unSupportChains.length) {
3025
- throw new Error((0, _utils9.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
3399
+ throw new Error((0, _utils10.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
3026
3400
  }
3027
3401
  availableNamespaces[key] = namespace;
3028
3402
  }
3029
3403
  } else {
3030
- throw new Error((0, _utils9.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3404
+ throw new Error((0, _utils10.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
3031
3405
  }
3032
3406
  });
3033
- Object.entries(optionalNamespaces).forEach(_ref59 => {
3034
- let [key, namespace] = _ref59;
3407
+ Object.entries(optionalNamespaces).forEach(_ref63 => {
3408
+ let [key, namespace] = _ref63;
3035
3409
  if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
3036
3410
  if (namespace.chains) {
3037
3411
  const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
@@ -3055,8 +3429,8 @@ class KoniExtension {
3055
3429
  }
3056
3430
  }
3057
3431
  });
3058
- Object.entries(availableNamespaces).forEach(_ref60 => {
3059
- let [key, namespace] = _ref60;
3432
+ Object.entries(availableNamespaces).forEach(_ref64 => {
3433
+ let [key, namespace] = _ref64;
3060
3434
  if (namespace.chains) {
3061
3435
  const accounts = selectedAccounts.filter(address => {
3062
3436
  const [_namespace] = address.split(':');
@@ -3080,10 +3454,10 @@ class KoniExtension {
3080
3454
  request.resolve();
3081
3455
  return true;
3082
3456
  }
3083
- async rejectWalletConnectSession(_ref61) {
3457
+ async rejectWalletConnectSession(_ref65) {
3084
3458
  let {
3085
3459
  id
3086
- } = _ref61;
3460
+ } = _ref65;
3087
3461
  const request = this.#koniState.requestService.getConnectWCRequest(id);
3088
3462
  const wcId = request.request.id;
3089
3463
  if ((0, _helpers2.isProposalExpired)(request.request.params)) {
@@ -3105,10 +3479,10 @@ class KoniExtension {
3105
3479
  });
3106
3480
  return this.#koniState.walletConnectService.sessions;
3107
3481
  }
3108
- async disconnectWalletConnectSession(_ref62) {
3482
+ async disconnectWalletConnectSession(_ref66) {
3109
3483
  let {
3110
3484
  topic
3111
- } = _ref62;
3485
+ } = _ref66;
3112
3486
  await this.#koniState.walletConnectService.disconnect(topic);
3113
3487
  return true;
3114
3488
  }
@@ -3121,18 +3495,18 @@ class KoniExtension {
3121
3495
  });
3122
3496
  return this.#koniState.requestService.allNotSupportWCRequests;
3123
3497
  }
3124
- approveWalletConnectNotSupport(_ref63) {
3498
+ approveWalletConnectNotSupport(_ref67) {
3125
3499
  let {
3126
3500
  id
3127
- } = _ref63;
3501
+ } = _ref67;
3128
3502
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3129
3503
  request.resolve();
3130
3504
  return true;
3131
3505
  }
3132
- rejectWalletConnectNotSupport(_ref64) {
3506
+ rejectWalletConnectNotSupport(_ref68) {
3133
3507
  let {
3134
3508
  id
3135
- } = _ref64;
3509
+ } = _ref68;
3136
3510
  const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3137
3511
  request.reject(new Error('USER_REJECTED'));
3138
3512
  return true;
@@ -3140,11 +3514,11 @@ class KoniExtension {
3140
3514
 
3141
3515
  /// Manta
3142
3516
 
3143
- async enableMantaPay(_ref65) {
3517
+ async enableMantaPay(_ref69) {
3144
3518
  let {
3145
3519
  address,
3146
3520
  password
3147
- } = _ref65;
3521
+ } = _ref69;
3148
3522
  // always takes the current account
3149
3523
  function timeout() {
3150
3524
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -3234,11 +3608,11 @@ class KoniExtension {
3234
3608
  async disableMantaPay(address) {
3235
3609
  return this.#koniState.disableMantaPay(address);
3236
3610
  }
3237
- async isTonBounceableAddress(_ref66) {
3611
+ async isTonBounceableAddress(_ref70) {
3238
3612
  let {
3239
3613
  address,
3240
3614
  chain
3241
- } = _ref66;
3615
+ } = _ref70;
3242
3616
  try {
3243
3617
  const tonApi = this.#koniState.getTonApi(chain);
3244
3618
  const state = await tonApi.getAccountState(address);
@@ -3284,10 +3658,10 @@ class KoniExtension {
3284
3658
 
3285
3659
  /* Metadata */
3286
3660
 
3287
- async findRawMetadata(_ref67) {
3661
+ async findRawMetadata(_ref71) {
3288
3662
  let {
3289
3663
  genesisHash
3290
- } = _ref67;
3664
+ } = _ref71;
3291
3665
  const {
3292
3666
  metadata,
3293
3667
  specVersion,
@@ -3301,20 +3675,20 @@ class KoniExtension {
3301
3675
  userExtensions
3302
3676
  };
3303
3677
  }
3304
- async calculateMetadataHash(_ref68) {
3678
+ async calculateMetadataHash(_ref72) {
3305
3679
  let {
3306
3680
  chain
3307
- } = _ref68;
3681
+ } = _ref72;
3308
3682
  const hash = await this.#koniState.calculateMetadataHash(chain);
3309
3683
  return {
3310
3684
  metadataHash: hash || ''
3311
3685
  };
3312
3686
  }
3313
- async shortenMetadata(_ref69) {
3687
+ async shortenMetadata(_ref73) {
3314
3688
  let {
3315
3689
  chain,
3316
3690
  txBlob
3317
- } = _ref69;
3691
+ } = _ref73;
3318
3692
  const shorten = await this.#koniState.shortenMetadata(chain, txBlob);
3319
3693
  return {
3320
3694
  txMetadata: shorten || ''
@@ -3667,18 +4041,18 @@ class KoniExtension {
3667
4041
 
3668
4042
  /* Campaign */
3669
4043
 
3670
- unlockDotCheckCanMint(_ref70) {
4044
+ unlockDotCheckCanMint(_ref74) {
3671
4045
  let {
3672
4046
  address,
3673
4047
  network,
3674
4048
  slug
3675
- } = _ref70;
4049
+ } = _ref74;
3676
4050
  return this.#koniState.mintCampaignService.unlockDotCampaign.canMint(address, slug, network);
3677
4051
  }
3678
- unlockDotSubscribeMintedData(id, port, _ref71) {
4052
+ unlockDotSubscribeMintedData(id, port, _ref75) {
3679
4053
  let {
3680
4054
  transactionId
3681
- } = _ref71;
4055
+ } = _ref75;
3682
4056
  const cb = (0, _subscriptions.createSubscription)(id, port);
3683
4057
  const subscription = this.#koniState.mintCampaignService.unlockDotCampaign.subscribeMintedNft(transactionId, cb);
3684
4058
  this.createUnsubscriptionHandle(id, subscription.unsubscribe);
@@ -3710,10 +4084,10 @@ class KoniExtension {
3710
4084
  });
3711
4085
  return filterBanner(await this.#koniState.campaignService.getProcessingCampaign());
3712
4086
  }
3713
- async completeCampaignBanner(_ref72) {
4087
+ async completeCampaignBanner(_ref76) {
3714
4088
  let {
3715
4089
  slug
3716
- } = _ref72;
4090
+ } = _ref76;
3717
4091
  const campaign = await this.#koniState.dbService.getCampaign(slug);
3718
4092
  if (campaign) {
3719
4093
  await this.#koniState.dbService.upsertCampaign({
@@ -4248,8 +4622,8 @@ class KoniExtension {
4248
4622
  resolve();
4249
4623
  }
4250
4624
  };
4251
- this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref73 => {
4252
- let [_unsub, rs] = _ref73;
4625
+ this.#koniState.balanceService.subscribeTransferableBalance(address, waitXcmData.chain, waitXcmData.token, waitXcmData.nextTxType, onRs).then(_ref77 => {
4626
+ let [_unsub, rs] = _ref77;
4253
4627
  unsub = _unsub;
4254
4628
  onRs(rs);
4255
4629
  }).catch(console.error);
@@ -4680,6 +5054,8 @@ class KoniExtension {
4680
5054
  return await this.updateAssetSetting(request);
4681
5055
  case 'pri(transfer.subscribe)':
4682
5056
  return this.subscribeMaxTransferable(request, id, port);
5057
+ case 'pri(transfer.confirmation.subscribe)':
5058
+ return this.subscribeTransferableWhenConfirmation(request, id, port);
4683
5059
  case 'pri(freeBalance.get)':
4684
5060
  return this.getAddressTransferableBalance(request);
4685
5061
  case 'pri(freeBalance.subscribe)':
@@ -4698,6 +5074,10 @@ class KoniExtension {
4698
5074
  /// Transfer
4699
5075
  case 'pri(accounts.transfer)':
4700
5076
  return await this.makeTransfer(request);
5077
+ case 'pri(accounts.bitcoin.dapp.transfer.confirmation)':
5078
+ return await this.makeBitcoinDappTransferConfirmation(request);
5079
+ case 'pri(accounts.psbt.transfer.confirmation)':
5080
+ return await this.makePsbtTransferAfterConfirmation(request);
4701
5081
  case 'pri(accounts.crossChainTransfer)':
4702
5082
  return await this.makeCrossChainTransfer(request);
4703
5083
  case 'pri(accounts.getOptimalTransferProcess)':
@@ -4730,12 +5110,16 @@ class KoniExtension {
4730
5110
  return this.subscribeConfirmationsTon(id, port);
4731
5111
  case 'pri(confirmationsCardano.subscribe)':
4732
5112
  return this.subscribeConfirmationsCardano(id, port);
5113
+ case 'pri(confirmationsBitcoin.subscribe)':
5114
+ return this.subscribeConfirmationsBitcoin(id, port);
4733
5115
  case 'pri(confirmations.complete)':
4734
5116
  return await this.completeConfirmation(request);
4735
5117
  case 'pri(confirmationsTon.complete)':
4736
5118
  return await this.completeConfirmationTon(request);
4737
5119
  case 'pri(confirmationsCardano.complete)':
4738
5120
  return await this.completeConfirmationCardano(request);
5121
+ case 'pri(confirmationsBitcoin.complete)':
5122
+ return await this.completeConfirmationBitcoin(request);
4739
5123
 
4740
5124
  /// Stake
4741
5125
  case 'pri(bonding.getBondingOptions)':