@subwallet/extension-base 1.3.41-0 → 1.3.43-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +134 -5
- package/background/KoniTypes.js +18 -0
- package/background/errors/BitcoinProviderError.d.ts +6 -0
- package/background/errors/BitcoinProviderError.js +47 -0
- package/background/types.d.ts +1 -1
- package/cjs/background/KoniTypes.js +20 -1
- package/cjs/background/errors/BitcoinProviderError.js +54 -0
- package/cjs/constants/bitcoin.js +22 -0
- package/cjs/constants/index.js +16 -1
- package/cjs/core/logic-validation/recipientAddress.js +9 -0
- package/cjs/core/logic-validation/request.js +316 -3
- package/cjs/core/logic-validation/transfer.js +25 -5
- package/cjs/core/types.js +1 -0
- package/cjs/core/utils.js +15 -1
- package/cjs/koni/background/handlers/Extension.js +477 -93
- package/cjs/koni/background/handlers/State.js +249 -16
- package/cjs/koni/background/handlers/Tabs.js +119 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/bitcoin/index.js +67 -0
- package/cjs/page/index.js +5 -0
- package/cjs/services/balance-service/helpers/subscribe/bitcoin.js +94 -0
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -7
- package/cjs/services/balance-service/index.js +32 -4
- package/cjs/services/balance-service/transfer/bitcoin-transfer.js +119 -0
- package/cjs/services/balance-service/transfer/token.js +2 -0
- package/cjs/services/base/types.js +2 -0
- package/cjs/services/buy-service/index.js +17 -2
- package/cjs/services/chain-service/constants.js +14 -3
- package/cjs/services/chain-service/handler/bitcoin/BitcoinApi.js +105 -0
- package/cjs/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +78 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +371 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +19 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +368 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +302 -0
- package/cjs/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/cjs/services/chain-service/index.js +27 -3
- package/cjs/services/chain-service/utils/index.js +57 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +27 -5
- package/cjs/services/event-service/index.js +4 -0
- package/cjs/services/fee-service/service.js +8 -3
- package/cjs/services/hiro-service/index.js +96 -0
- package/cjs/services/hiro-service/utils/index.js +85 -0
- package/cjs/services/history-service/bitcoin-history.js +58 -0
- package/cjs/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/cjs/services/history-service/index.js +41 -3
- package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Migration.js +2 -2
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/cjs/services/migration-service/scripts/MigrateNewUnifiedAccount.js +29 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/request-service/handler/AuthRequestHandler.js +18 -0
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +427 -0
- package/cjs/services/request-service/index.js +29 -3
- package/cjs/services/rune-service/index.js +105 -0
- package/cjs/services/transaction-service/helpers/index.js +7 -1
- package/cjs/services/transaction-service/index.js +206 -16
- package/cjs/services/transaction-service/utils.js +6 -3
- package/cjs/strategy/api-request-strategy/context/base.js +31 -0
- package/cjs/strategy/api-request-strategy/index.js +90 -0
- package/cjs/strategy/api-request-strategy/types.js +1 -0
- package/cjs/strategy/api-request-strategy/utils/index.js +33 -0
- package/cjs/types/account/info/keyring.js +1 -1
- package/cjs/types/bitcoin.js +24 -0
- package/cjs/types/fee/bitcoin.js +1 -0
- package/cjs/types/fee/index.js +11 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/account/analyze.js +3 -3
- package/cjs/utils/account/common.js +16 -6
- package/cjs/utils/account/derive/info/solo.js +68 -19
- package/cjs/utils/account/derive/info/unified.js +2 -0
- package/cjs/utils/account/derive/validate.js +70 -2
- package/cjs/utils/account/transform.js +11 -5
- package/cjs/utils/auth.js +2 -1
- package/cjs/utils/bitcoin/common.js +98 -0
- package/cjs/utils/bitcoin/fee.js +21 -0
- package/cjs/utils/bitcoin/index.js +38 -0
- package/cjs/utils/bitcoin/utxo-management.js +281 -0
- package/cjs/utils/fee/transfer.js +48 -0
- package/cjs/utils/index.js +15 -1
- package/constants/bitcoin.d.ts +3 -0
- package/constants/bitcoin.js +13 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +3 -1
- package/core/logic-validation/recipientAddress.js +10 -1
- package/core/logic-validation/request.d.ts +6 -2
- package/core/logic-validation/request.js +309 -3
- package/core/logic-validation/transfer.d.ts +2 -2
- package/core/logic-validation/transfer.js +27 -7
- package/core/types.d.ts +1 -0
- package/core/types.js +1 -0
- package/core/utils.d.ts +1 -0
- package/core/utils.js +15 -2
- package/koni/background/handlers/Extension.d.ts +5 -0
- package/koni/background/handlers/Extension.js +387 -9
- package/koni/background/handlers/State.d.ts +10 -3
- package/koni/background/handlers/State.js +240 -15
- package/koni/background/handlers/Tabs.d.ts +7 -2
- package/koni/background/handlers/Tabs.js +119 -9
- package/package.json +149 -8
- package/packageInfo.js +1 -1
- package/page/bitcoin/index.d.ts +17 -0
- package/page/bitcoin/index.js +60 -0
- package/page/index.d.ts +2 -1
- package/page/index.js +4 -0
- package/services/balance-service/helpers/subscribe/bitcoin.d.ts +2 -0
- package/services/balance-service/helpers/subscribe/bitcoin.js +87 -0
- package/services/balance-service/helpers/subscribe/index.d.ts +2 -2
- package/services/balance-service/helpers/subscribe/index.js +20 -8
- package/services/balance-service/index.d.ts +2 -0
- package/services/balance-service/index.js +32 -4
- package/services/balance-service/transfer/bitcoin-transfer.d.ts +14 -0
- package/services/balance-service/transfer/bitcoin-transfer.js +112 -0
- package/services/balance-service/transfer/cardano-transfer.d.ts +2 -0
- package/services/balance-service/transfer/token.js +2 -0
- package/services/base/types.d.ts +2 -0
- package/services/base/types.js +2 -0
- package/services/buy-service/index.js +17 -2
- package/services/chain-service/constants.d.ts +6 -0
- package/services/chain-service/constants.js +8 -2
- package/services/chain-service/handler/bitcoin/BitcoinApi.d.ts +31 -0
- package/services/chain-service/handler/bitcoin/BitcoinApi.js +98 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.d.ts +16 -0
- package/services/chain-service/handler/bitcoin/BitcoinChainHandler.js +70 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/blockstream-testnet-strategy.js +362 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.d.ts +2 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/index.js +5 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/BlockStreamTestnet/mempool-testnet-strategy.js +359 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.d.ts +28 -0
- package/services/chain-service/handler/bitcoin/strategy/SubWalletMainnet/index.js +293 -0
- package/services/chain-service/handler/bitcoin/strategy/types.d.ts +291 -0
- package/services/chain-service/handler/bitcoin/strategy/types.js +1 -0
- package/services/chain-service/index.d.ts +3 -0
- package/services/chain-service/index.js +31 -5
- package/services/chain-service/types.d.ts +20 -0
- package/services/chain-service/utils/index.d.ts +4 -0
- package/services/chain-service/utils/index.js +50 -4
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/native-staking/para-chain.js +27 -5
- package/services/event-service/index.d.ts +3 -0
- package/services/event-service/index.js +4 -0
- package/services/event-service/types.d.ts +3 -0
- package/services/fee-service/service.js +8 -3
- package/services/hiro-service/index.d.ts +17 -0
- package/services/hiro-service/index.js +88 -0
- package/services/hiro-service/utils/index.d.ts +6 -0
- package/services/hiro-service/utils/index.js +72 -0
- package/services/history-service/bitcoin-history.d.ts +4 -0
- package/services/history-service/bitcoin-history.js +52 -0
- package/services/history-service/helpers/recoverHistoryStatus.d.ts +3 -1
- package/services/history-service/helpers/recoverHistoryStatus.js +96 -4
- package/services/history-service/index.d.ts +1 -0
- package/services/history-service/index.js +42 -4
- package/services/keyring-service/context/handlers/Derive.js +2 -2
- package/services/keyring-service/context/handlers/Migration.js +2 -2
- package/services/keyring-service/context/handlers/Mnemonic.js +4 -3
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.d.ts +4 -0
- package/services/migration-service/scripts/MigrateNewUnifiedAccount.js +21 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +19 -1
- package/services/request-service/handler/BitcoinRequestHandler.d.ts +22 -0
- package/services/request-service/handler/BitcoinRequestHandler.js +414 -0
- package/services/request-service/index.d.ts +8 -2
- package/services/request-service/index.js +25 -3
- package/services/rune-service/index.d.ts +17 -0
- package/services/rune-service/index.js +97 -0
- package/services/transaction-service/helpers/index.d.ts +3 -1
- package/services/transaction-service/helpers/index.js +5 -0
- package/services/transaction-service/index.d.ts +4 -5
- package/services/transaction-service/index.js +205 -17
- package/services/transaction-service/types.d.ts +13 -2
- package/services/transaction-service/utils.js +7 -4
- package/strategy/api-request-strategy/context/base.d.ts +15 -0
- package/strategy/api-request-strategy/context/base.js +24 -0
- package/strategy/api-request-strategy/index.d.ts +15 -0
- package/strategy/api-request-strategy/index.js +83 -0
- package/strategy/api-request-strategy/types.d.ts +22 -0
- package/strategy/api-request-strategy/types.js +1 -0
- package/strategy/api-request-strategy/utils/index.d.ts +2 -0
- package/strategy/api-request-strategy/utils/index.js +23 -0
- package/types/account/info/keyring.d.ts +1 -1
- package/types/account/info/keyring.js +1 -1
- package/types/balance/index.d.ts +4 -1
- package/types/balance/transfer.d.ts +19 -0
- package/types/bitcoin.d.ts +93 -0
- package/types/bitcoin.js +17 -0
- package/types/buy.d.ts +1 -1
- package/types/fee/base.d.ts +4 -1
- package/types/fee/bitcoin.d.ts +18 -0
- package/types/fee/bitcoin.js +1 -0
- package/types/fee/index.d.ts +1 -0
- package/types/fee/index.js +2 -1
- package/types/fee/subscription.d.ts +4 -3
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/account/analyze.js +4 -4
- package/utils/account/common.d.ts +7 -8
- package/utils/account/common.js +16 -6
- package/utils/account/derive/info/solo.js +70 -21
- package/utils/account/derive/info/unified.js +2 -0
- package/utils/account/derive/validate.d.ts +1 -0
- package/utils/account/derive/validate.js +68 -1
- package/utils/account/transform.d.ts +1 -1
- package/utils/account/transform.js +11 -5
- package/utils/auth.js +3 -2
- package/utils/bitcoin/common.d.ts +22 -0
- package/utils/bitcoin/common.js +88 -0
- package/utils/bitcoin/fee.d.ts +2 -0
- package/utils/bitcoin/fee.js +14 -0
- package/utils/bitcoin/index.d.ts +3 -0
- package/utils/bitcoin/index.js +6 -0
- package/utils/bitcoin/utxo-management.d.ts +33 -0
- package/utils/bitcoin/utxo-management.js +266 -0
- package/utils/fee/transfer.d.ts +3 -1
- package/utils/fee/transfer.js +47 -1
- package/utils/index.d.ts +1 -0
- package/utils/index.js +6 -3
|
@@ -14,11 +14,16 @@ exports.validateTypedSignMessageDataV3V4 = validateTypedSignMessageDataV3V4;
|
|
|
14
14
|
exports.validationAuthCardanoMiddleware = validationAuthCardanoMiddleware;
|
|
15
15
|
exports.validationAuthMiddleware = validationAuthMiddleware;
|
|
16
16
|
exports.validationAuthWCMiddleware = validationAuthWCMiddleware;
|
|
17
|
+
exports.validationBitcoinConnectMiddleware = validationBitcoinConnectMiddleware;
|
|
18
|
+
exports.validationBitcoinSendTransactionMiddleware = validationBitcoinSendTransactionMiddleware;
|
|
19
|
+
exports.validationBitcoinSignMessageMiddleware = validationBitcoinSignMessageMiddleware;
|
|
20
|
+
exports.validationBitcoinSignPsbtMiddleware = validationBitcoinSignPsbtMiddleware;
|
|
17
21
|
exports.validationCardanoSignDataMiddleware = validationCardanoSignDataMiddleware;
|
|
18
22
|
exports.validationConnectMiddleware = validationConnectMiddleware;
|
|
19
23
|
exports.validationEvmDataTransactionMiddleware = validationEvmDataTransactionMiddleware;
|
|
20
24
|
exports.validationEvmSignMessageMiddleware = validationEvmSignMessageMiddleware;
|
|
21
25
|
var _ethSigUtil = require("@metamask/eth-sig-util");
|
|
26
|
+
var _BitcoinProviderError = require("@subwallet/extension-base/background/errors/BitcoinProviderError");
|
|
22
27
|
var _CardanoProviderError = require("@subwallet/extension-base/background/errors/CardanoProviderError");
|
|
23
28
|
var _EvmProviderError = require("@subwallet/extension-base/background/errors/EvmProviderError");
|
|
24
29
|
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
@@ -29,8 +34,10 @@ var _cardano = require("@subwallet/extension-base/utils/cardano");
|
|
|
29
34
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
30
35
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
31
36
|
var _keyring = require("@subwallet/keyring");
|
|
37
|
+
var _utils2 = require("@subwallet/keyring/utils");
|
|
38
|
+
var _validate = require("@subwallet/keyring/utils/address/validate");
|
|
32
39
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
33
|
-
var
|
|
40
|
+
var _utils3 = require("@walletconnect/utils");
|
|
34
41
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
35
42
|
var _bn = _interopRequireDefault(require("bn.js"));
|
|
36
43
|
var _i18next = require("i18next");
|
|
@@ -172,6 +179,9 @@ async function validationAuthMiddleware(koni, url, payload) {
|
|
|
172
179
|
if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[payload.pair.address]) {
|
|
173
180
|
return handleAuthError(payload, 'Account not in allowed list', 'dApp', errors);
|
|
174
181
|
}
|
|
182
|
+
if (payload.pair.meta.noPublicKey) {
|
|
183
|
+
return handleAuthError(payload, (0, _i18next.t)('This account is not supported for this action'), 'dApp', errors);
|
|
184
|
+
}
|
|
175
185
|
payload.authInfo = authInfo;
|
|
176
186
|
}
|
|
177
187
|
} catch (e) {
|
|
@@ -180,6 +190,8 @@ async function validationAuthMiddleware(koni, url, payload) {
|
|
|
180
190
|
}
|
|
181
191
|
return payload;
|
|
182
192
|
}
|
|
193
|
+
|
|
194
|
+
// ====== EVM ======
|
|
183
195
|
async function validationConnectMiddleware(koni, url, payload) {
|
|
184
196
|
let currentChain;
|
|
185
197
|
let autoActiveChain = false;
|
|
@@ -521,7 +533,7 @@ function validationAuthWCMiddleware(koni, url, payload, topic) {
|
|
|
521
533
|
} = payload;
|
|
522
534
|
if (!topic) {
|
|
523
535
|
payload.errorPosition = 'dApp';
|
|
524
|
-
errors.push(new Error((0,
|
|
536
|
+
errors.push(new Error((0, _utils3.getSdkError)('UNAUTHORIZED_EXTEND_REQUEST').message));
|
|
525
537
|
} else {
|
|
526
538
|
const requestSession = koni.walletConnectService.getSession(topic);
|
|
527
539
|
let sessionAccounts = [];
|
|
@@ -601,6 +613,11 @@ async function validationAuthCardanoMiddleware(koni, url, payload) {
|
|
|
601
613
|
}
|
|
602
614
|
return payload;
|
|
603
615
|
}
|
|
616
|
+
|
|
617
|
+
// ====== EVM ======
|
|
618
|
+
|
|
619
|
+
// ====== Cardano ======
|
|
620
|
+
|
|
604
621
|
async function validationCardanoSignDataMiddleware(koni, url, payload_) {
|
|
605
622
|
const {
|
|
606
623
|
address,
|
|
@@ -657,11 +674,298 @@ async function validationCardanoSignDataMiddleware(koni, url, payload_) {
|
|
|
657
674
|
});
|
|
658
675
|
return promise;
|
|
659
676
|
}
|
|
677
|
+
|
|
678
|
+
// ====== Cardano ======
|
|
679
|
+
|
|
680
|
+
// ====== Bitcoin ======
|
|
681
|
+
|
|
682
|
+
async function validationBitcoinConnectMiddleware(koni, url, payload) {
|
|
683
|
+
const {
|
|
684
|
+
authInfo,
|
|
685
|
+
errors,
|
|
686
|
+
networkKey
|
|
687
|
+
} = payload;
|
|
688
|
+
let autoActiveChain = false;
|
|
689
|
+
const handleError = message_ => {
|
|
690
|
+
payload.errorPosition = 'ui';
|
|
691
|
+
payload.confirmationType = 'errorConnectNetwork';
|
|
692
|
+
const [message, name] = convertErrorMessage(message_);
|
|
693
|
+
const error = new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS, message, undefined, name);
|
|
694
|
+
console.error(error);
|
|
695
|
+
errors.push(error);
|
|
696
|
+
};
|
|
697
|
+
if (url && authInfo) {
|
|
698
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
699
|
+
autoActiveChain = true;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
const currentBitcoinNetwork = koni.requestService.getDAppChainInfo({
|
|
703
|
+
autoActive: autoActiveChain,
|
|
704
|
+
accessType: 'bitcoin',
|
|
705
|
+
defaultChain: networkKey,
|
|
706
|
+
url
|
|
707
|
+
});
|
|
708
|
+
if (currentBitcoinNetwork) {
|
|
709
|
+
const chainStatus = koni.getChainStateByKey(networkKey);
|
|
710
|
+
const chainInfo = koni.getChainInfo(networkKey);
|
|
711
|
+
if (!chainStatus.active) {
|
|
712
|
+
try {
|
|
713
|
+
await koni.chainService.enableChain(networkKey);
|
|
714
|
+
} catch (e) {
|
|
715
|
+
handleError('Can not active chain: ' + chainInfo.name);
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
} else {
|
|
719
|
+
handleError('This network is currently not supported');
|
|
720
|
+
}
|
|
721
|
+
return {
|
|
722
|
+
...payload,
|
|
723
|
+
networkKey: (currentBitcoinNetwork === null || currentBitcoinNetwork === void 0 ? void 0 : currentBitcoinNetwork.slug) || networkKey,
|
|
724
|
+
errors
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
async function validationBitcoinSignMessageMiddleware(koni, url, payload_) {
|
|
728
|
+
const {
|
|
729
|
+
address,
|
|
730
|
+
errors,
|
|
731
|
+
pair: pair_
|
|
732
|
+
} = payload_;
|
|
733
|
+
const message = payload_.payloadAfterValidated;
|
|
734
|
+
const {
|
|
735
|
+
promise,
|
|
736
|
+
resolve
|
|
737
|
+
} = (0, _utils.createPromiseHandler)();
|
|
738
|
+
const handleError = message_ => {
|
|
739
|
+
payload_.errorPosition = 'ui';
|
|
740
|
+
payload_.confirmationType = 'bitcoinSignatureRequest';
|
|
741
|
+
const [message, name] = convertErrorMessage(message_);
|
|
742
|
+
const error = new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
743
|
+
console.error(error);
|
|
744
|
+
errors.push(error);
|
|
745
|
+
};
|
|
746
|
+
if (address === '' || !message) {
|
|
747
|
+
handleError((0, _i18next.t)('not found address or payload to sign'));
|
|
748
|
+
}
|
|
749
|
+
if (!(0, _validate.isBitcoinAddress)(address)) {
|
|
750
|
+
handleError((0, _i18next.t)('Invalid bitcoin address'));
|
|
751
|
+
}
|
|
752
|
+
const pair = pair_ || _uiKeyring.keyring.getPair(address);
|
|
753
|
+
if (!pair) {
|
|
754
|
+
handleError((0, _i18next.t)('Unable to find account'));
|
|
755
|
+
}
|
|
756
|
+
const hashPayload = '';
|
|
757
|
+
let canSign = false;
|
|
758
|
+
if (!(pair !== null && pair !== void 0 && pair.meta.isExtneral)) {
|
|
759
|
+
canSign = true;
|
|
760
|
+
}
|
|
761
|
+
const payloadAfterValidated = {
|
|
762
|
+
address,
|
|
763
|
+
payload: message,
|
|
764
|
+
payloadJson: message,
|
|
765
|
+
hashPayload,
|
|
766
|
+
canSign,
|
|
767
|
+
id: ''
|
|
768
|
+
};
|
|
769
|
+
resolve({
|
|
770
|
+
...payload_,
|
|
771
|
+
errors,
|
|
772
|
+
payloadAfterValidated
|
|
773
|
+
});
|
|
774
|
+
return promise;
|
|
775
|
+
}
|
|
776
|
+
async function validationBitcoinSignPsbtMiddleware(koni, url, payload_) {
|
|
777
|
+
const {
|
|
778
|
+
errors,
|
|
779
|
+
networkKey,
|
|
780
|
+
pair: pair_
|
|
781
|
+
} = payload_;
|
|
782
|
+
const psbtParams = payload_.payloadAfterValidated;
|
|
783
|
+
const {
|
|
784
|
+
address,
|
|
785
|
+
allowedSighash,
|
|
786
|
+
autoFinalized,
|
|
787
|
+
broadcast,
|
|
788
|
+
psbt,
|
|
789
|
+
signAtIndex
|
|
790
|
+
} = payload_.payloadAfterValidated;
|
|
791
|
+
const {
|
|
792
|
+
promise,
|
|
793
|
+
resolve
|
|
794
|
+
} = (0, _utils.createPromiseHandler)();
|
|
795
|
+
const handleError = message_ => {
|
|
796
|
+
payload_.errorPosition = 'ui';
|
|
797
|
+
payload_.confirmationType = 'bitcoinSignPsbtRequest';
|
|
798
|
+
const [message, name] = convertErrorMessage(message_);
|
|
799
|
+
const error = new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
800
|
+
console.error(error);
|
|
801
|
+
errors.push(error);
|
|
802
|
+
};
|
|
803
|
+
if (!(psbtParams.network === 'mainnet' || psbtParams.network === 'testnet')) {
|
|
804
|
+
handleError((0, _i18next.t)('Network to try this request is must be mainnet or testnet'));
|
|
805
|
+
}
|
|
806
|
+
if (!networkKey) {
|
|
807
|
+
handleError((0, _i18next.t)('Network unavailable. Please switch network or manually add network to wallet'));
|
|
808
|
+
}
|
|
809
|
+
if (!psbt || !address) {
|
|
810
|
+
handleError((0, _i18next.t)('Not found payload to sign'));
|
|
811
|
+
}
|
|
812
|
+
if (!(0, _util.isHex)(`0x${psbt}`)) {
|
|
813
|
+
handleError((0, _i18next.t)('Psbt to be signed must be hex-encoded'));
|
|
814
|
+
}
|
|
815
|
+
if (!(0, _validate.isBitcoinAddress)(address)) {
|
|
816
|
+
handleError((0, _i18next.t)('Not found address'));
|
|
817
|
+
}
|
|
818
|
+
const addressInfo = (0, _utils2.getBitcoinAddressInfo)(address);
|
|
819
|
+
if (psbtParams.network !== addressInfo.network) {
|
|
820
|
+
handleError((0, _i18next.t)('The account or the network is not matched'));
|
|
821
|
+
}
|
|
822
|
+
const payload = {
|
|
823
|
+
broadcast: !!broadcast,
|
|
824
|
+
network: networkKey,
|
|
825
|
+
signAtIndex: (0, _util.isArray)(signAtIndex) && signAtIndex.length === 0 ? undefined : signAtIndex,
|
|
826
|
+
address,
|
|
827
|
+
allowedSighash,
|
|
828
|
+
autoFinalized
|
|
829
|
+
};
|
|
830
|
+
const hashPayload = '';
|
|
831
|
+
const pair = pair_ || _uiKeyring.keyring.getPair(address);
|
|
832
|
+
const canSign = !(pair !== null && pair !== void 0 && pair.meta.isExternal);
|
|
833
|
+
const signPayload = {
|
|
834
|
+
address,
|
|
835
|
+
payload,
|
|
836
|
+
hashPayload,
|
|
837
|
+
canSign
|
|
838
|
+
};
|
|
839
|
+
resolve({
|
|
840
|
+
...payload_,
|
|
841
|
+
errors,
|
|
842
|
+
payloadAfterValidated: signPayload
|
|
843
|
+
});
|
|
844
|
+
return promise;
|
|
845
|
+
}
|
|
846
|
+
async function validationBitcoinSendTransactionMiddleware(koni, url, payload_) {
|
|
847
|
+
var _transactionParams$re, _transactionParams$re2;
|
|
848
|
+
const {
|
|
849
|
+
address,
|
|
850
|
+
errors,
|
|
851
|
+
networkKey,
|
|
852
|
+
pair: pair_
|
|
853
|
+
} = payload_;
|
|
854
|
+
const transactionParams = payload_.payloadAfterValidated;
|
|
855
|
+
const {
|
|
856
|
+
promise,
|
|
857
|
+
resolve
|
|
858
|
+
} = (0, _utils.createPromiseHandler)();
|
|
859
|
+
const senderAccountInfo = (0, _utils2.getBitcoinAddressInfo)(address);
|
|
860
|
+
const handleError = message_ => {
|
|
861
|
+
payload_.errorPosition = 'ui';
|
|
862
|
+
payload_.confirmationType = 'bitcoinSendTransactionRequestAfterConfirmation';
|
|
863
|
+
const [message, name] = convertErrorMessage(message_);
|
|
864
|
+
const error = new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
865
|
+
console.error(error);
|
|
866
|
+
errors.push(error);
|
|
867
|
+
};
|
|
868
|
+
const autoFormatNumber = val => {
|
|
869
|
+
if (typeof val === 'string' && val.startsWith('0x')) {
|
|
870
|
+
return new _bignumber.default(val.replace('0x', ''), 16).toString();
|
|
871
|
+
} else if (typeof val === 'number') {
|
|
872
|
+
return val.toString();
|
|
873
|
+
}
|
|
874
|
+
return val;
|
|
875
|
+
};
|
|
876
|
+
if (transactionParams.network !== senderAccountInfo.network) {
|
|
877
|
+
handleError((0, _i18next.t)('The account or the network is not matched'));
|
|
878
|
+
}
|
|
879
|
+
if (!((_transactionParams$re = transactionParams.recipients) !== null && _transactionParams$re !== void 0 && _transactionParams$re.length)) {
|
|
880
|
+
handleError((0, _i18next.t)('please provide the recipient and the amount'));
|
|
881
|
+
}
|
|
882
|
+
if (((_transactionParams$re2 = transactionParams.recipients) === null || _transactionParams$re2 === void 0 ? void 0 : _transactionParams$re2.length) > 1) {
|
|
883
|
+
handleError((0, _i18next.t)("we don't support multiple recipients yet. Please provide only one for now."));
|
|
884
|
+
}
|
|
885
|
+
if (transactionParams.recipients.filter(_ref => {
|
|
886
|
+
let {
|
|
887
|
+
address,
|
|
888
|
+
amount
|
|
889
|
+
} = _ref;
|
|
890
|
+
return !address || !amount;
|
|
891
|
+
}).length > 0) {
|
|
892
|
+
throw new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS);
|
|
893
|
+
}
|
|
894
|
+
const recipientAccountInfo = (0, _utils2.getBitcoinAddressInfo)(transactionParams.recipients[0].address);
|
|
895
|
+
if (recipientAccountInfo.network !== transactionParams.network) {
|
|
896
|
+
handleError((0, _i18next.t)('invalid recipient address'));
|
|
897
|
+
}
|
|
898
|
+
if (transactionParams.recipients.length !== 1) {
|
|
899
|
+
handleError((0, _i18next.t)('receiving address must be a single account'));
|
|
900
|
+
}
|
|
901
|
+
if (address === transactionParams.recipients[0].address) {
|
|
902
|
+
handleError((0, _i18next.t)('must be different from sending address'));
|
|
903
|
+
}
|
|
904
|
+
const pair = pair_ || _uiKeyring.keyring.getPair(address);
|
|
905
|
+
if (!pair) {
|
|
906
|
+
handleError((0, _i18next.t)('unable to find account'));
|
|
907
|
+
}
|
|
908
|
+
const tokenInfo = koni.getNativeTokenInfo(networkKey);
|
|
909
|
+
let freeBalance = {
|
|
910
|
+
decimals: 0,
|
|
911
|
+
symbol: 'BTC',
|
|
912
|
+
value: '0'
|
|
913
|
+
};
|
|
914
|
+
let totalValue = new _bignumber.default('0');
|
|
915
|
+
try {
|
|
916
|
+
freeBalance = await koni.balanceService.getTransferableBalance(address, networkKey, tokenInfo.slug);
|
|
917
|
+
} catch (e) {
|
|
918
|
+
const message = e.message;
|
|
919
|
+
if (message.toLowerCase().includes((0, _i18next.t)('please enable network'))) {
|
|
920
|
+
const chainInfo = koni.chainService.getChainInfoByKey(networkKey);
|
|
921
|
+
payload_.errorPosition = 'ui';
|
|
922
|
+
payload_.confirmationType = 'bitcoinSendTransactionRequestAfterConfirmation';
|
|
923
|
+
const [message, name] = [(0, _i18next.t)('Enable {{chain}} network on the extension and try again', {
|
|
924
|
+
replace: {
|
|
925
|
+
chain: chainInfo.name
|
|
926
|
+
}
|
|
927
|
+
}), (0, _i18next.t)('Network not enabled')];
|
|
928
|
+
const error = new _BitcoinProviderError.BitcoinProviderError(_KoniTypes.BitcoinProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
929
|
+
console.error(error);
|
|
930
|
+
errors.push(error);
|
|
931
|
+
} else {
|
|
932
|
+
handleError(message);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
const to = transactionParams.recipients.map(value => {
|
|
936
|
+
const amount = autoFormatNumber(value.amount);
|
|
937
|
+
totalValue = totalValue.plus(amount);
|
|
938
|
+
return {
|
|
939
|
+
...value,
|
|
940
|
+
amount
|
|
941
|
+
};
|
|
942
|
+
});
|
|
943
|
+
if (new _bignumber.default(freeBalance.value).lte(totalValue)) {
|
|
944
|
+
handleError((0, _i18next.t)('insufficient balance'));
|
|
945
|
+
}
|
|
946
|
+
const sendTransactionRequest = {
|
|
947
|
+
networkKey,
|
|
948
|
+
address,
|
|
949
|
+
canSign: !pair.meta.isExternal,
|
|
950
|
+
value: totalValue.toString(),
|
|
951
|
+
to,
|
|
952
|
+
tokenSlug: tokenInfo.slug
|
|
953
|
+
};
|
|
954
|
+
resolve({
|
|
955
|
+
...payload_,
|
|
956
|
+
errors,
|
|
957
|
+
payloadAfterValidated: sendTransactionRequest
|
|
958
|
+
});
|
|
959
|
+
return promise;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// ====== Bitcoin ======
|
|
963
|
+
|
|
660
964
|
function convertErrorMessage(message_, name) {
|
|
661
965
|
const message = message_.toLowerCase();
|
|
662
966
|
|
|
663
967
|
// Network error
|
|
664
|
-
if (message.includes('connection error') || message.includes('connection not open') || message.includes('connection timeout') || message.includes('can not active chain') || message.includes('invalid json rpc')) {
|
|
968
|
+
if (message.includes('connection error') || message.includes('connection not open') || message.includes('connection timeout') || message.includes('can not active chain') || message.includes('invalid json rpc') || message.includes('internet connection')) {
|
|
665
969
|
return [(0, _i18next.t)('Re-enable the network or change RPC on the extension and try again'), (0, _i18next.t)('Unstable network connection')];
|
|
666
970
|
}
|
|
667
971
|
if (message.includes('network is currently not supported')) {
|
|
@@ -696,6 +1000,15 @@ function convertErrorMessage(message_, name) {
|
|
|
696
1000
|
if (message.includes('the sender address must be the ethereum address type')) {
|
|
697
1001
|
return [(0, _i18next.t)('The sender address must be the ethereum address type'), (0, _i18next.t)('Invalid address type')];
|
|
698
1002
|
}
|
|
1003
|
+
if (message.includes('the sender address must be the ethereum address type')) {
|
|
1004
|
+
return [(0, _i18next.t)('The sender address must be the bitcoin address type'), (0, _i18next.t)('Invalid address type')];
|
|
1005
|
+
}
|
|
1006
|
+
if (message.includes('account or the network is not matched')) {
|
|
1007
|
+
return [(0, _i18next.t)('The account does not match the selected network'), (0, _i18next.t)('Invalid address type')];
|
|
1008
|
+
}
|
|
1009
|
+
if (message.includes('receiving address must be a single account')) {
|
|
1010
|
+
return [(0, _i18next.t)('The receiving address must be a single account'), (0, _i18next.t)('Invalid recipient address')];
|
|
1011
|
+
}
|
|
699
1012
|
if (message.includes('insufficient balance') || message.includes('insufficient funds')) {
|
|
700
1013
|
return [(0, _i18next.t)('Insufficient balance on the sender address. Top up your balance and try again'), (0, _i18next.t)('Unable to sign transaction')];
|
|
701
1014
|
}
|
|
@@ -328,6 +328,11 @@ async function estimateFeeForTransaction(validationResponse, transaction, chainI
|
|
|
328
328
|
} = (0, _utils3._getChainNativeTokenBasicInfo)(chainInfo);
|
|
329
329
|
estimateFee.decimals = decimals;
|
|
330
330
|
estimateFee.symbol = symbol;
|
|
331
|
+
const {
|
|
332
|
+
address,
|
|
333
|
+
feeCustom,
|
|
334
|
+
feeOption
|
|
335
|
+
} = validationResponse;
|
|
331
336
|
if (transaction) {
|
|
332
337
|
try {
|
|
333
338
|
if ((0, _helpers.isSubstrateTransaction)(transaction)) {
|
|
@@ -337,13 +342,28 @@ async function estimateFeeForTransaction(validationResponse, transaction, chainI
|
|
|
337
342
|
estimateFee.value = transaction.estimateFee; // todo: might need to update logic estimate fee inside for future actions excluding normal transfer Ton and Jetton
|
|
338
343
|
} else if ((0, _helpers.isCardanoTransaction)(transaction)) {
|
|
339
344
|
estimateFee.value = transaction.estimateCardanoFee;
|
|
345
|
+
} else if ((0, _helpers.isBitcoinTransaction)(transaction)) {
|
|
346
|
+
const feeCombine = (0, _utils5.combineBitcoinFee)(feeInfo, feeOption, feeCustom);
|
|
347
|
+
const recipients = [];
|
|
348
|
+
for (const txOutput of transaction.txOutputs) {
|
|
349
|
+
txOutput.address && recipients.push(txOutput.address);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// TODO: Need review
|
|
353
|
+
const sizeInfo = (0, _utils5.getSizeInfo)({
|
|
354
|
+
inputLength: transaction.inputCount,
|
|
355
|
+
recipients: recipients,
|
|
356
|
+
sender: address
|
|
357
|
+
});
|
|
358
|
+
estimateFee.value = Math.ceil(feeCombine.feeRate * sizeInfo.txVBytes).toString();
|
|
340
359
|
} else {
|
|
341
|
-
const
|
|
360
|
+
const _transaction = transaction;
|
|
361
|
+
const gasLimit = _transaction.gas || (await evmApi.api.eth.estimateGas(_transaction));
|
|
342
362
|
const feeCombine = (0, _utils5.combineEthFee)(feeInfo, validationResponse.feeOption, validationResponse.feeCustom);
|
|
343
|
-
if (
|
|
344
|
-
estimateFee.value = new _bignumber.default(
|
|
345
|
-
} else if (
|
|
346
|
-
estimateFee.value = new _bignumber.default(
|
|
363
|
+
if (_transaction.maxFeePerGas) {
|
|
364
|
+
estimateFee.value = new _bignumber.default(_transaction.maxFeePerGas.toString()).multipliedBy(gasLimit).toFixed(0);
|
|
365
|
+
} else if (_transaction.gasPrice) {
|
|
366
|
+
estimateFee.value = new _bignumber.default(_transaction.gasPrice.toString()).multipliedBy(gasLimit).toFixed(0);
|
|
347
367
|
} else {
|
|
348
368
|
if (feeCombine.maxFeePerGas) {
|
|
349
369
|
const maxFee = new _bignumber.default(feeCombine.maxFeePerGas); // TODO: Need review
|
package/cjs/core/types.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.ValidationCondition = ValidationCondition;
|
|
|
15
15
|
ValidationCondition["IS_VALID_SUBSTRATE_ADDRESS_FORMAT"] = "IS_VALID_SUBSTRATE_ADDRESS_FORMAT";
|
|
16
16
|
ValidationCondition["IS_VALID_TON_ADDRESS_FORMAT"] = "IS_VALID_TON_ADDRESS_FORMAT";
|
|
17
17
|
ValidationCondition["IS_VALID_CARDANO_ADDRESS_FORMAT"] = "IS_VALID_CARDANO_ADDRESS_FORMAT";
|
|
18
|
+
ValidationCondition["IS_VALID_BITCOIN_ADDRESS_FORMAT"] = "IS_VALID_BITCOIN_ADDRESS_FORMAT";
|
|
18
19
|
ValidationCondition["IS_NOT_DUPLICATE_ADDRESS"] = "IS_NOT_DUPLICATE_ADDRESS";
|
|
19
20
|
ValidationCondition["IS_SUPPORT_LEDGER_ACCOUNT"] = "IS_SUPPORT_LEDGER_ACCOUNT";
|
|
20
21
|
})(ValidationCondition || (exports.ValidationCondition = ValidationCondition = {}));
|
package/cjs/core/utils.js
CHANGED
|
@@ -10,6 +10,7 @@ exports._isNotNull = _isNotNull;
|
|
|
10
10
|
exports._isSufficientToken = void 0;
|
|
11
11
|
exports._isSupportLedgerAccount = _isSupportLedgerAccount;
|
|
12
12
|
exports._isValidAddressForEcosystem = _isValidAddressForEcosystem;
|
|
13
|
+
exports._isValidBitcoinAddressFormat = _isValidBitcoinAddressFormat;
|
|
13
14
|
exports._isValidCardanoAddressFormat = _isValidCardanoAddressFormat;
|
|
14
15
|
exports._isValidSubstrateAddressFormat = _isValidSubstrateAddressFormat;
|
|
15
16
|
exports._isValidTonAddressFormat = _isValidTonAddressFormat;
|
|
@@ -23,6 +24,7 @@ var _utils = require("@subwallet/extension-base/services/balance-service/helpers
|
|
|
23
24
|
var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
24
25
|
var _utils3 = require("@subwallet/extension-base/utils");
|
|
25
26
|
var _keyring = require("@subwallet/keyring");
|
|
27
|
+
var _utils4 = require("@subwallet/keyring/utils");
|
|
26
28
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
27
29
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
28
30
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -73,7 +75,7 @@ function _isValidAddressForEcosystem(validateRecipientParams) {
|
|
|
73
75
|
toAddress
|
|
74
76
|
} = validateRecipientParams;
|
|
75
77
|
if (!(0, _utils3.isAddressAndChainCompatible)(toAddress, destChainInfo)) {
|
|
76
|
-
if ((0, _utils2._isChainEvmCompatible)(destChainInfo) || (0, _utils2._isChainSubstrateCompatible)(destChainInfo) || (0, _utils2._isChainTonCompatible)(destChainInfo) || (0, _utils2._isChainCardanoCompatible)(destChainInfo)) {
|
|
78
|
+
if ((0, _utils2._isChainEvmCompatible)(destChainInfo) || (0, _utils2._isChainSubstrateCompatible)(destChainInfo) || (0, _utils2._isChainTonCompatible)(destChainInfo) || (0, _utils2._isChainCardanoCompatible)(destChainInfo) || (0, _utils2._isChainBitcoinCompatible)(destChainInfo)) {
|
|
77
79
|
return 'Recipient address must be the same type as sender address';
|
|
78
80
|
}
|
|
79
81
|
return 'Unknown chain type';
|
|
@@ -114,6 +116,18 @@ function _isValidCardanoAddressFormat(validateRecipientParams) {
|
|
|
114
116
|
}
|
|
115
117
|
return '';
|
|
116
118
|
}
|
|
119
|
+
function _isValidBitcoinAddressFormat(validateRecipientParams) {
|
|
120
|
+
var _destChainInfo$bitcoi;
|
|
121
|
+
const {
|
|
122
|
+
destChainInfo,
|
|
123
|
+
toAddress
|
|
124
|
+
} = validateRecipientParams;
|
|
125
|
+
const addressInfo = (0, _utils4.validateBitcoinAddress)(toAddress) ? (0, _utils4.getBitcoinAddressInfo)(toAddress) : null;
|
|
126
|
+
if ((addressInfo === null || addressInfo === void 0 ? void 0 : addressInfo.network) !== ((_destChainInfo$bitcoi = destChainInfo.bitcoinInfo) === null || _destChainInfo$bitcoi === void 0 ? void 0 : _destChainInfo$bitcoi.bitcoinNetwork)) {
|
|
127
|
+
return `Recipient address must be a valid ${destChainInfo.name} address`;
|
|
128
|
+
}
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
117
131
|
function _isNotDuplicateAddress(validateRecipientParams) {
|
|
118
132
|
const {
|
|
119
133
|
fromAddress,
|