@subwallet/extension-base 1.3.31-0 → 1.3.32-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 +70 -3
- package/background/KoniTypes.js +14 -0
- package/background/errors/CardanoProviderError.d.ts +6 -0
- package/background/errors/CardanoProviderError.js +61 -0
- package/background/types.d.ts +2 -2
- package/cjs/background/KoniTypes.js +16 -1
- package/cjs/background/errors/CardanoProviderError.js +67 -0
- package/cjs/constants/index.js +4 -1
- package/cjs/core/logic-validation/request.js +50 -3
- package/cjs/koni/api/contract-handler/evm/web3.js +21 -0
- package/cjs/koni/api/staking/bonding/utils.js +24 -3
- package/cjs/koni/background/handlers/Extension.js +115 -107
- package/cjs/koni/background/handlers/State.js +228 -5
- package/cjs/koni/background/handlers/Tabs.js +277 -55
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/cardano/cips/cip30.js +63 -0
- package/cjs/page/cardano/cips/index.js +20 -0
- package/cjs/page/cardano/index.js +41 -0
- package/cjs/page/{SubWalleEvmProvider.js → evm/index.js} +2 -2
- package/cjs/page/index.js +9 -4
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +33 -1
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +6 -2
- package/cjs/services/balance-service/transfer/xcm/index.js +2 -0
- package/cjs/services/chain-service/handler/CardanoApi.js +33 -0
- package/cjs/services/chain-service/index.js +31 -0
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +2 -2
- package/cjs/services/earning-service/handlers/native-staking/mythos.js +42 -8
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
- package/cjs/services/earning-service/handlers/native-staking/tao.js +13 -13
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
- package/cjs/services/request-service/constants.js +3 -1
- package/cjs/services/request-service/handler/AuthRequestHandler.js +38 -5
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +45 -3
- package/cjs/services/request-service/helper/index.js +419 -1
- package/cjs/services/swap-service/handler/asset-hub/handler.js +1 -1
- package/cjs/services/swap-service/handler/base-handler.js +81 -21
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/cjs/services/swap-service/handler/uniswap-handler.js +274 -45
- package/cjs/services/swap-service/index.js +33 -11
- package/cjs/services/swap-service/utils.js +15 -2
- package/cjs/utils/auth.js +2 -1
- package/cjs/utils/cardano.js +20 -0
- package/cjs/utils/index.js +4 -4
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/logic-validation/request.d.ts +6 -2
- package/core/logic-validation/request.js +51 -5
- package/koni/api/contract-handler/evm/web3.d.ts +2 -0
- package/koni/api/contract-handler/evm/web3.js +19 -0
- package/koni/api/staking/bonding/utils.d.ts +2 -1
- package/koni/api/staking/bonding/utils.js +23 -3
- package/koni/background/handlers/Extension.js +7 -2
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +223 -4
- package/koni/background/handlers/Tabs.d.ts +11 -1
- package/koni/background/handlers/Tabs.js +242 -19
- package/package.json +62 -42
- package/packageInfo.js +1 -1
- package/page/cardano/cips/cip30.d.ts +22 -0
- package/page/cardano/cips/cip30.js +55 -0
- package/page/cardano/cips/index.d.ts +3 -0
- package/page/cardano/cips/index.js +7 -0
- package/page/cardano/index.d.ts +13 -0
- package/page/cardano/index.js +34 -0
- package/page/{SubWalleEvmProvider.d.ts → evm/index.d.ts} +3 -2
- package/page/{SubWalleEvmProvider.js → evm/index.js} +1 -1
- package/page/index.d.ts +3 -2
- package/page/index.js +6 -2
- package/page/{Accounts.d.ts → substrate/Accounts.d.ts} +1 -1
- package/page/{Metadata.d.ts → substrate/Metadata.d.ts} +1 -1
- package/page/{PostMessageProvider.d.ts → substrate/PostMessageProvider.d.ts} +1 -1
- package/page/{Signer.d.ts → substrate/Signer.d.ts} +1 -1
- package/page/{Injected.d.ts → substrate/index.d.ts} +1 -1
- package/services/balance-service/helpers/subscribe/cardano/types.d.ts +14 -0
- package/services/balance-service/helpers/subscribe/substrate/index.js +34 -2
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +4 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +4 -1
- package/services/balance-service/transfer/xcm/index.js +2 -0
- package/services/chain-service/handler/CardanoApi.d.ts +3 -1
- package/services/chain-service/handler/CardanoApi.js +33 -0
- package/services/chain-service/index.d.ts +5 -1
- package/services/chain-service/index.js +32 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +3 -3
- package/services/earning-service/handlers/native-staking/dtao.js +2 -2
- package/services/earning-service/handlers/native-staking/mythos.js +42 -8
- package/services/earning-service/handlers/native-staking/relay-chain.js +1 -1
- package/services/earning-service/handlers/native-staking/tao.js +14 -14
- package/services/earning-service/handlers/nomination-pool/index.js +1 -1
- package/services/migration-service/scripts/MigrateAuthUrls.js +1 -1
- package/services/request-service/constants.js +3 -1
- package/services/request-service/handler/AuthRequestHandler.js +40 -7
- package/services/request-service/handler/CardanoRequestHandler.d.ts +2 -0
- package/services/request-service/handler/CardanoRequestHandler.js +45 -3
- package/services/request-service/helper/index.d.ts +54 -0
- package/services/request-service/helper/index.js +406 -1
- package/services/request-service/types.d.ts +3 -1
- package/services/swap-service/handler/asset-hub/handler.js +1 -1
- package/services/swap-service/handler/base-handler.d.ts +3 -1
- package/services/swap-service/handler/base-handler.js +82 -22
- package/services/swap-service/handler/hydradx-handler.js +1 -1
- package/services/swap-service/handler/uniswap-handler.d.ts +5 -0
- package/services/swap-service/handler/uniswap-handler.js +275 -46
- package/services/swap-service/index.js +34 -12
- package/services/swap-service/utils.d.ts +3 -2
- package/services/swap-service/utils.js +13 -1
- package/types/swap/index.d.ts +1 -0
- package/types/transaction/process.d.ts +2 -0
- package/utils/auth.js +3 -2
- package/utils/cardano.d.ts +2 -0
- package/utils/cardano.js +12 -0
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -1
- package/cjs/utils/canDerive.js +0 -12
- package/utils/canDerive.d.ts +0 -2
- package/utils/canDerive.js +0 -6
- /package/cjs/page/{Accounts.js → substrate/Accounts.js} +0 -0
- /package/cjs/page/{Metadata.js → substrate/Metadata.js} +0 -0
- /package/cjs/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
- /package/cjs/page/{Signer.js → substrate/Signer.js} +0 -0
- /package/cjs/page/{Injected.js → substrate/index.js} +0 -0
- /package/page/{Accounts.js → substrate/Accounts.js} +0 -0
- /package/page/{Metadata.js → substrate/Metadata.js} +0 -0
- /package/page/{PostMessageProvider.js → substrate/PostMessageProvider.js} +0 -0
- /package/page/{Signer.js → substrate/Signer.js} +0 -0
- /package/page/{Injected.js → substrate/index.js} +0 -0
package/cjs/utils/auth.js
CHANGED
|
@@ -14,7 +14,8 @@ const isAddressValidWithAuthType = (address, accountAuthTypes) => {
|
|
|
14
14
|
const validTypes = {
|
|
15
15
|
evm: _types.EthereumKeypairTypes,
|
|
16
16
|
substrate: _types.SubstrateKeypairTypes,
|
|
17
|
-
ton: _types.TonKeypairTypes
|
|
17
|
+
ton: _types.TonKeypairTypes,
|
|
18
|
+
cardano: _types.CardanoKeypairTypes
|
|
18
19
|
};
|
|
19
20
|
return !!(accountAuthTypes !== null && accountAuthTypes !== void 0 && accountAuthTypes.some(authType => {
|
|
20
21
|
var _validTypes$authType;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.convertCardanoHexToBech32 = exports.convertCardanoAddressToHex = void 0;
|
|
7
|
+
var _cardanoSerializationLibNodejs = require("@emurgo/cardano-serialization-lib-nodejs");
|
|
8
|
+
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
const convertCardanoAddressToHex = bech32Address => {
|
|
12
|
+
const addr = _cardanoSerializationLibNodejs.Address.from_bech32(bech32Address);
|
|
13
|
+
return addr.to_hex();
|
|
14
|
+
};
|
|
15
|
+
exports.convertCardanoAddressToHex = convertCardanoAddressToHex;
|
|
16
|
+
const convertCardanoHexToBech32 = hexAddress => {
|
|
17
|
+
const addr = _cardanoSerializationLibNodejs.Address.from_hex(hexAddress);
|
|
18
|
+
return addr.to_bech32();
|
|
19
|
+
};
|
|
20
|
+
exports.convertCardanoHexToBech32 = convertCardanoHexToBech32;
|
package/cjs/utils/index.js
CHANGED
|
@@ -36,13 +36,13 @@ var _exportNames = {
|
|
|
36
36
|
baseParseIPFSUrl: true,
|
|
37
37
|
swParseIPFSUrl: true,
|
|
38
38
|
wait: true,
|
|
39
|
-
|
|
39
|
+
convertCardanoAddressToHex: true
|
|
40
40
|
};
|
|
41
41
|
exports.baseParseIPFSUrl = void 0;
|
|
42
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "convertCardanoAddressToHex", {
|
|
43
43
|
enumerable: true,
|
|
44
44
|
get: function () {
|
|
45
|
-
return
|
|
45
|
+
return _cardano.convertCardanoAddressToHex;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
exports.convertFundStatus = void 0;
|
|
@@ -77,7 +77,6 @@ var _keyring = require("@subwallet/keyring");
|
|
|
77
77
|
var _i18next = require("i18next");
|
|
78
78
|
var _util = require("@polkadot/util");
|
|
79
79
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
80
|
-
var _canDerive = require("./canDerive");
|
|
81
80
|
var _mv = require("./mv3");
|
|
82
81
|
Object.keys(_mv).forEach(function (key) {
|
|
83
82
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -102,6 +101,7 @@ Object.keys(_fetch).forEach(function (key) {
|
|
|
102
101
|
}
|
|
103
102
|
});
|
|
104
103
|
});
|
|
104
|
+
var _cardano = require("./cardano");
|
|
105
105
|
var _account2 = require("./account");
|
|
106
106
|
Object.keys(_account2).forEach(function (key) {
|
|
107
107
|
if (key === "default" || key === "__esModule") return;
|
package/constants/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare const IGNORE_QR_SIGNER: string[];
|
|
|
31
31
|
export declare const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
32
32
|
export declare const XCM_FEE_RATIO = 2;
|
|
33
33
|
export declare const GAS_PRICE_RATIO: number;
|
|
34
|
+
export declare const MAX_COLLATERAL_AMOUNT = "5000000";
|
|
34
35
|
export declare const NETWORK_MULTI_GAS_FEE: string[];
|
|
35
36
|
export declare const ORDINAL_COLLECTION = "__Ordinal__";
|
|
36
37
|
export declare const ORDINAL_METHODS: string[];
|
package/constants/index.js
CHANGED
|
@@ -33,6 +33,7 @@ export const IGNORE_QR_SIGNER = [];
|
|
|
33
33
|
export const XCM_MIN_AMOUNT_RATIO = 1.2;
|
|
34
34
|
export const XCM_FEE_RATIO = 2;
|
|
35
35
|
export const GAS_PRICE_RATIO = 1 + 2 / 100;
|
|
36
|
+
export const MAX_COLLATERAL_AMOUNT = '5000000';
|
|
36
37
|
export const NETWORK_MULTI_GAS_FEE = ['*'];
|
|
37
38
|
export const ORDINAL_COLLECTION = '__Ordinal__';
|
|
38
39
|
export const ORDINAL_METHODS = ['drc-20', 'pol-20'];
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { ConfirmationType, ErrorValidation } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { ConfirmationType, ConfirmationTypeCardano, ErrorValidation } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
import { AccountAuthType } from '@subwallet/extension-base/background/types';
|
|
2
3
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
4
|
import { AuthUrlInfo } from '@subwallet/extension-base/services/request-service/types';
|
|
4
5
|
import { KeyringPair } from '@subwallet/keyring/types';
|
|
5
6
|
import Joi from 'joi';
|
|
6
7
|
export declare type ValidateStepFunction = (koni: KoniState, url: string, payload: PayloadValidated, topic?: string) => Promise<PayloadValidated>;
|
|
8
|
+
export declare type RequestAccountType = 'substrate' | 'evm' | 'ton' | 'cardano';
|
|
7
9
|
export interface PayloadValidated {
|
|
8
10
|
networkKey: string;
|
|
9
11
|
address: string;
|
|
10
12
|
pair?: KeyringPair;
|
|
11
13
|
authInfo?: AuthUrlInfo;
|
|
14
|
+
type: AccountAuthType;
|
|
12
15
|
method?: string;
|
|
13
16
|
payloadAfterValidated: any;
|
|
14
17
|
errorPosition?: 'dApp' | 'ui';
|
|
15
|
-
confirmationType?: ConfirmationType;
|
|
18
|
+
confirmationType?: ConfirmationType | ConfirmationTypeCardano;
|
|
16
19
|
errors: Error[];
|
|
17
20
|
}
|
|
18
21
|
export declare type SignTypedDataMessageV3V4 = {
|
|
@@ -40,5 +43,6 @@ export declare function validationConnectMiddleware(koni: KoniState, url: string
|
|
|
40
43
|
export declare function validationEvmDataTransactionMiddleware(koni: KoniState, url: string, payload: PayloadValidated): Promise<PayloadValidated>;
|
|
41
44
|
export declare function validationEvmSignMessageMiddleware(koni: KoniState, url: string, payload_: PayloadValidated): Promise<PayloadValidated>;
|
|
42
45
|
export declare function validationAuthWCMiddleware(koni: KoniState, url: string, payload: PayloadValidated, topic?: string): Promise<PayloadValidated>;
|
|
46
|
+
export declare function validationCardanoSignDataMiddleware(koni: KoniState, url: string, payload_: PayloadValidated): Promise<PayloadValidated>;
|
|
43
47
|
export declare function convertErrorMessage(message_: string, name?: string): string[];
|
|
44
48
|
export declare function convertErrorFormat(errors: Error[]): ErrorValidation[];
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { typedSignatureHash } from '@metamask/eth-sig-util';
|
|
5
|
+
import { CardanoProviderError } from '@subwallet/extension-base/background/errors/CardanoProviderError';
|
|
5
6
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
6
7
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
7
|
-
import { EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
8
|
+
import { CardanoProviderErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
8
9
|
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
9
10
|
import { BN_ZERO, combineEthFee, createPromiseHandler, isSameAddress, stripUrl, wait } from '@subwallet/extension-base/utils';
|
|
10
11
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
11
12
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
12
|
-
import { isSubstrateAddress } from '@subwallet/keyring';
|
|
13
|
+
import { isCardanoAddress, isSubstrateAddress } from '@subwallet/keyring';
|
|
13
14
|
import { keyring } from '@subwallet/ui-keyring';
|
|
14
15
|
import { getSdkError } from '@walletconnect/utils';
|
|
15
16
|
import BigN from 'bignumber.js';
|
|
@@ -167,7 +168,8 @@ export async function validationConnectMiddleware(koni, url, payload) {
|
|
|
167
168
|
address,
|
|
168
169
|
authInfo,
|
|
169
170
|
errors,
|
|
170
|
-
networkKey
|
|
171
|
+
networkKey,
|
|
172
|
+
type
|
|
171
173
|
} = {
|
|
172
174
|
...payload
|
|
173
175
|
};
|
|
@@ -179,8 +181,8 @@ export async function validationConnectMiddleware(koni, url, payload) {
|
|
|
179
181
|
console.error(error);
|
|
180
182
|
errors.push(error);
|
|
181
183
|
};
|
|
182
|
-
if (authInfo !== null && authInfo !== void 0 && authInfo.
|
|
183
|
-
currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.
|
|
184
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.currentNetworkMap[type]) {
|
|
185
|
+
currentChain = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap[type];
|
|
184
186
|
}
|
|
185
187
|
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
186
188
|
autoActiveChain = true;
|
|
@@ -542,6 +544,50 @@ export function validationAuthWCMiddleware(koni, url, payload, topic) {
|
|
|
542
544
|
});
|
|
543
545
|
return promise;
|
|
544
546
|
}
|
|
547
|
+
export async function validationCardanoSignDataMiddleware(koni, url, payload_) {
|
|
548
|
+
const {
|
|
549
|
+
address,
|
|
550
|
+
errors,
|
|
551
|
+
pair: pair_
|
|
552
|
+
} = payload_;
|
|
553
|
+
const payload = payload_.payloadAfterValidated;
|
|
554
|
+
const {
|
|
555
|
+
promise,
|
|
556
|
+
resolve
|
|
557
|
+
} = createPromiseHandler();
|
|
558
|
+
let canSign = false;
|
|
559
|
+
const handleError = message_ => {
|
|
560
|
+
payload_.errorPosition = 'ui';
|
|
561
|
+
payload_.confirmationType = 'cardanoSignatureRequest';
|
|
562
|
+
const [message, name] = convertErrorMessage(message_);
|
|
563
|
+
const error = new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, message, undefined, name);
|
|
564
|
+
console.error(error);
|
|
565
|
+
errors.push(error);
|
|
566
|
+
};
|
|
567
|
+
if (address === '' || !payload) {
|
|
568
|
+
handleError('Not found address or payload to sign');
|
|
569
|
+
}
|
|
570
|
+
if (!isCardanoAddress(address)) {
|
|
571
|
+
handleError('Not found cardano address');
|
|
572
|
+
}
|
|
573
|
+
const pair = pair_ || keyring.getPair(address);
|
|
574
|
+
if (!(pair !== null && pair !== void 0 && pair.meta.isExtneral)) {
|
|
575
|
+
canSign = true;
|
|
576
|
+
}
|
|
577
|
+
const payloadAfterValidated = {
|
|
578
|
+
address,
|
|
579
|
+
payload: payload,
|
|
580
|
+
hashPayload: payload,
|
|
581
|
+
canSign: canSign,
|
|
582
|
+
id: ''
|
|
583
|
+
};
|
|
584
|
+
resolve({
|
|
585
|
+
...payload_,
|
|
586
|
+
errors,
|
|
587
|
+
payloadAfterValidated
|
|
588
|
+
});
|
|
589
|
+
return promise;
|
|
590
|
+
}
|
|
545
591
|
export function convertErrorMessage(message_, name) {
|
|
546
592
|
const message = message_.toLowerCase();
|
|
547
593
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
3
4
|
import { TransactionConfig } from 'web3-core';
|
|
4
5
|
import { Contract } from 'web3-eth-contract';
|
|
5
6
|
export declare const getERC20Contract: (assetAddress: string, evmApi: _EvmApi, options?: {}) => Contract;
|
|
6
7
|
export declare function getWeb3Contract(contractAddress: _Address, evmApi: _EvmApi, contractAbi: Record<string, any>, options?: {}): Contract;
|
|
7
8
|
export declare function getERC20Allowance(spender: _Address, owner: _Address, contractAddress: _Address, evmApi: _EvmApi): Promise<string>;
|
|
8
9
|
export declare function getERC20SpendingApprovalTx(spender: _Address, owner: _Address, contractAddress: _Address, evmApi: _EvmApi, amount?: string): Promise<TransactionConfig>;
|
|
10
|
+
export declare function estimateTxFee(tx: TransactionConfig, evmApi: _EvmApi, feeInfo: EvmFeeInfo): Promise<string>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { _ERC20_ABI } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
5
5
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
6
6
|
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
7
|
+
import BigNumber from 'bignumber.js';
|
|
7
8
|
export const getERC20Contract = (assetAddress, evmApi, options = {}) => {
|
|
8
9
|
// @ts-ignore
|
|
9
10
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
|
|
@@ -42,4 +43,22 @@ export async function getERC20SpendingApprovalTx(spender, owner, contractAddress
|
|
|
42
43
|
gasPrice: priority.gasPrice,
|
|
43
44
|
...feeCombine
|
|
44
45
|
};
|
|
46
|
+
}
|
|
47
|
+
export async function estimateTxFee(tx, evmApi, feeInfo) {
|
|
48
|
+
const gasLimit = tx.gas || (await evmApi.api.eth.estimateGas(tx));
|
|
49
|
+
const feeCombine = combineEthFee(feeInfo);
|
|
50
|
+
let estimatedFee;
|
|
51
|
+
if (tx.maxFeePerGas) {
|
|
52
|
+
estimatedFee = BigNumber(tx.maxFeePerGas.toString()).multipliedBy(gasLimit).toFixed(0);
|
|
53
|
+
} else if (tx.gasPrice) {
|
|
54
|
+
estimatedFee = BigNumber(tx.gasPrice.toString()).multipliedBy(gasLimit).toFixed(0);
|
|
55
|
+
} else {
|
|
56
|
+
if (feeCombine.maxFeePerGas) {
|
|
57
|
+
estimatedFee = BigNumber(feeCombine.maxFeePerGas).multipliedBy(gasLimit).toFixed(0);
|
|
58
|
+
} else if (feeCombine.gasPrice) {
|
|
59
|
+
estimatedFee = BigNumber(feeCombine.gasPrice).multipliedBy(gasLimit).toFixed(0);
|
|
60
|
+
}
|
|
61
|
+
estimatedFee = '0';
|
|
62
|
+
}
|
|
63
|
+
return estimatedFee;
|
|
45
64
|
}
|
|
@@ -100,9 +100,10 @@ export declare function calcInflationUniformEraPayout(totalIssuance: BN, yearlyI
|
|
|
100
100
|
export declare function calcInflationRewardCurve(minInflation: number, stakedFraction: number, idealStake: number, idealInterest: number, falloff: number): number;
|
|
101
101
|
export declare function calculateInflation(totalEraStake: BN, totalIssuance: BN, numAuctions: number, networkKey: string): number;
|
|
102
102
|
export declare function calculateChainStakedReturn(inflation: number, totalEraStake: BN, totalIssuance: BN, networkKey: string): number;
|
|
103
|
-
export declare function calculateChainStakedReturnV2(chainInfo: _ChainInfo, totalIssuance: string, erasPerDay: number, lastTotalStaked: string, validatorEraReward: BigNumber, inflation: BigNumber, isCompound?: boolean): number
|
|
103
|
+
export declare function calculateChainStakedReturnV2(chainInfo: _ChainInfo, totalIssuance: string, erasPerDay: number, lastTotalStaked: string, validatorEraReward: BigNumber, inflation: BigNumber, isCompound?: boolean): Promise<number | undefined>;
|
|
104
104
|
export declare function calculateAlephZeroValidatorReturn(chainStakedReturn: number, commission: number): number;
|
|
105
105
|
export declare function calculateTernoaValidatorReturn(rewardPerValidator: number, validatorStake: number, commission: number): number;
|
|
106
|
+
export declare function calculateAnalogChainStakedReturn(): Promise<number | undefined>;
|
|
106
107
|
export declare function calculateValidatorStakedReturn(chainStakedReturn: number, totalValidatorStake: BN, avgStake: BN, commission: number): number;
|
|
107
108
|
export declare function getCommission(commissionString: string): number;
|
|
108
109
|
export interface InflationConfig {
|
|
@@ -72,10 +72,9 @@ export function calculateChainStakedReturn(inflation, totalEraStake, totalIssuan
|
|
|
72
72
|
|
|
73
73
|
return stakedReturn;
|
|
74
74
|
}
|
|
75
|
-
export function calculateChainStakedReturnV2(chainInfo, totalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, inflation, isCompound) {
|
|
75
|
+
export async function calculateChainStakedReturnV2(chainInfo, totalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, inflation, isCompound) {
|
|
76
76
|
if (chainInfo.slug === 'analog_timechain') {
|
|
77
|
-
|
|
78
|
-
return 55;
|
|
77
|
+
return await calculateAnalogChainStakedReturn();
|
|
79
78
|
}
|
|
80
79
|
const DAYS_PER_YEAR = 365;
|
|
81
80
|
const {
|
|
@@ -104,6 +103,27 @@ export function calculateTernoaValidatorReturn(rewardPerValidator, validatorStak
|
|
|
104
103
|
const stakeRatio = rewardForNominators / validatorStake;
|
|
105
104
|
return stakeRatio * 365 * 100;
|
|
106
105
|
}
|
|
106
|
+
export async function calculateAnalogChainStakedReturn() {
|
|
107
|
+
const url = 'https://explorer-api.analog.one/api/nominations?projection=apy,rewardsClaimed,eraEndsTime';
|
|
108
|
+
try {
|
|
109
|
+
var _apyInfo$data;
|
|
110
|
+
const response = await fetch(url, {
|
|
111
|
+
method: 'GET',
|
|
112
|
+
headers: {
|
|
113
|
+
'Content-Type': 'application/json'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
if (!response.ok) {
|
|
117
|
+
const errorText = await response.text();
|
|
118
|
+
throw new Error(`API error: ${response.status} - ${errorText}`);
|
|
119
|
+
}
|
|
120
|
+
const apyInfo = await response.json();
|
|
121
|
+
return apyInfo === null || apyInfo === void 0 ? void 0 : (_apyInfo$data = apyInfo.data) === null || _apyInfo$data === void 0 ? void 0 : _apyInfo$data.apy;
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.error('Fetch error:', e);
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
107
127
|
export function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
|
|
108
128
|
const bnAdjusted = avgStake.mul(BN_HUNDRED).div(totalValidatorStake);
|
|
109
129
|
const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
|
|
@@ -49,7 +49,7 @@ import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, crea
|
|
|
49
49
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
50
50
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
51
51
|
import { getKeypairTypeByAddress, isAddress, isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
52
|
-
import { EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
52
|
+
import { CardanoKeypairTypes, EthereumKeypairTypes, SubstrateKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
53
53
|
import { keyring } from '@subwallet/ui-keyring';
|
|
54
54
|
import { getSdkError } from '@walletconnect/utils';
|
|
55
55
|
import BigN from 'bignumber.js';
|
|
@@ -561,7 +561,8 @@ export default class KoniExtension {
|
|
|
561
561
|
const validTypes = {
|
|
562
562
|
evm: EthereumKeypairTypes,
|
|
563
563
|
substrate: SubstrateKeypairTypes,
|
|
564
|
-
ton: TonKeypairTypes
|
|
564
|
+
ton: TonKeypairTypes,
|
|
565
|
+
cardano: CardanoKeypairTypes
|
|
565
566
|
};
|
|
566
567
|
return !!accountAuthTypes && accountAuthTypes.some(authType => {
|
|
567
568
|
var _validTypes$authType;
|
|
@@ -585,6 +586,10 @@ export default class KoniExtension {
|
|
|
585
586
|
accounts.forEach(({
|
|
586
587
|
address
|
|
587
588
|
}) => isTonAddress(address) && list.push(address));
|
|
589
|
+
} else if (accountAuthType === 'cardano') {
|
|
590
|
+
accounts.forEach(({
|
|
591
|
+
address
|
|
592
|
+
}) => isCardanoAddress(address) && list.push(address));
|
|
588
593
|
}
|
|
589
594
|
return list;
|
|
590
595
|
}, []);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="chrome" />
|
|
2
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
2
3
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
3
|
-
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueCardano, ConfirmationsQueueTon, CrowdloanItem, CrowdloanJson, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestConfirmationComplete, RequestConfirmationCompleteCardano, RequestConfirmationCompleteTon, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
|
+
import { AddTokenRequestExternal, AmountData, ApiMap, AuthRequestV2, ChainStakingMetadata, ConfirmationsQueue, ConfirmationsQueueCardano, ConfirmationsQueueTon, CrowdloanItem, CrowdloanJson, EvmSendTransactionParams, ExternalRequestPromise, MantaPayConfig, MantaPaySyncState, NftCollection, NftItem, NftJson, NominatorMetadata, RequestAccountExportPrivateKey, RequestCardanoSignData, RequestCardanoSignTransaction, RequestConfirmationComplete, RequestConfirmationCompleteCardano, RequestConfirmationCompleteTon, RequestCrowdloanContributions, RequestSettingsType, ResponseAccountExportPrivateKey, ResponseCardanoSignData, ResponseCardanoSignTransaction, ServiceInfo, SingleModeJson, StakingItem, StakingJson, StakingRewardItem, StakingRewardJson, StakingType, UiSettings } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning } from '@subwallet/extension-base/background/types';
|
|
5
6
|
import { EnvConfig } from '@subwallet/extension-base/constants';
|
|
6
7
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
@@ -216,6 +217,10 @@ export default class KoniState {
|
|
|
216
217
|
evmSign(id: string, url: string, method: string, params: any, topic?: string): Promise<string | undefined>;
|
|
217
218
|
calculateAllGasFeeOnChain(activeEvmChains: string[], timeout?: number): Promise<Record<string, EvmFeeInfo | null>>;
|
|
218
219
|
evmSendTransaction(id: string, url: string, transactionParams: EvmSendTransactionParams, networkKeyInit?: string, topic?: string): Promise<string | undefined>;
|
|
220
|
+
cardanoGetBalance(id: string, url: string, address: string): Promise<CardanoWasm.Value>;
|
|
221
|
+
cardanoSignData(id: string, url: string, params: RequestCardanoSignData, currentAddress: string): Promise<ResponseCardanoSignData>;
|
|
222
|
+
cardanoSignTx(id: string, url: string, param: RequestCardanoSignTransaction, currentAddress: string): Promise<ResponseCardanoSignTransaction>;
|
|
223
|
+
cardanoSubmitTx(id: string, url: string, txHex: string): Promise<string>;
|
|
219
224
|
getConfirmationsQueueSubject(): BehaviorSubject<ConfirmationsQueue>;
|
|
220
225
|
getConfirmationsQueueSubjectTon(): BehaviorSubject<ConfirmationsQueueTon>;
|
|
221
226
|
getConfirmationsQueueSubjectCardano(): BehaviorSubject<ConfirmationsQueueCardano>;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';
|
|
5
|
+
import { CardanoProviderError } from '@subwallet/extension-base/background/errors/CardanoProviderError';
|
|
4
6
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
5
7
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
6
8
|
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
7
|
-
import { APIItemState, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
9
|
+
import { APIItemState, CardanoProviderErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
8
10
|
import { BACKEND_API_URL, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
|
|
9
|
-
import { convertErrorFormat, generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
|
|
11
|
+
import { convertErrorFormat, generateValidationProcess, validationAuthMiddleware, validationAuthWCMiddleware, validationCardanoSignDataMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
|
|
10
12
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
11
13
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
12
14
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
@@ -29,6 +31,7 @@ import NotificationService from '@subwallet/extension-base/services/notification
|
|
|
29
31
|
import { PriceService } from '@subwallet/extension-base/services/price-service';
|
|
30
32
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
31
33
|
import { openPopup } from '@subwallet/extension-base/services/request-service/handler/PopupHandler';
|
|
34
|
+
import { convertAssetToValue, convertValueToAsset, extractKeyHashesFromCollaterals, extractKeyHashesFromRequiredSigners, extractKeyHashesFromScripts, extractKeyHashesFromWithdrawals, extractKeyHashFromCertificate, getBalanceAddressMap } from '@subwallet/extension-base/services/request-service/helper';
|
|
32
35
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
33
36
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
34
37
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
@@ -37,7 +40,8 @@ import TransactionService from '@subwallet/extension-base/services/transaction-s
|
|
|
37
40
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
38
41
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
39
42
|
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
40
|
-
import { addLazy, isManifestV3, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
|
|
43
|
+
import { addLazy, isManifestV3, isSameAddress, reformatAddress, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
|
|
44
|
+
import { convertCardanoHexToBech32 } from '@subwallet/extension-base/utils/cardano';
|
|
41
45
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
42
46
|
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
43
47
|
import { keyring } from '@subwallet/ui-keyring';
|
|
@@ -430,7 +434,7 @@ export default class KoniState {
|
|
|
430
434
|
if (chainInfo && !_isChainEnabled(chainState)) {
|
|
431
435
|
await this.enableChainWithPriorityAssets(networkKey);
|
|
432
436
|
}
|
|
433
|
-
authUrls[shortenUrl].
|
|
437
|
+
authUrls[shortenUrl].currentNetworkMap.evm = networkKey;
|
|
434
438
|
this.setAuthorize(authUrls);
|
|
435
439
|
} else {
|
|
436
440
|
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, t('Not found {{shortenUrl}} in auth list', {
|
|
@@ -877,6 +881,7 @@ export default class KoniState {
|
|
|
877
881
|
}
|
|
878
882
|
const payloadValidation = {
|
|
879
883
|
address,
|
|
884
|
+
type: 'evm',
|
|
880
885
|
payloadAfterValidated: payload,
|
|
881
886
|
method,
|
|
882
887
|
errors: [],
|
|
@@ -930,6 +935,7 @@ export default class KoniState {
|
|
|
930
935
|
async evmSendTransaction(id, url, transactionParams, networkKeyInit, topic) {
|
|
931
936
|
const payloadValidation = {
|
|
932
937
|
errors: [],
|
|
938
|
+
type: 'evm',
|
|
933
939
|
networkKey: networkKeyInit || '',
|
|
934
940
|
payloadAfterValidated: transactionParams,
|
|
935
941
|
address: transactionParams.from
|
|
@@ -1007,6 +1013,219 @@ export default class KoniState {
|
|
|
1007
1013
|
});
|
|
1008
1014
|
});
|
|
1009
1015
|
}
|
|
1016
|
+
async cardanoGetBalance(id, url, address) {
|
|
1017
|
+
const authInfoMap = await this.getAuthList();
|
|
1018
|
+
const authInfo = authInfoMap[stripUrl(url)];
|
|
1019
|
+
let networkKey = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
|
|
1020
|
+
const autoActiveChain = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.isAllowed) || false;
|
|
1021
|
+
const chainInfo = this.requestService.getDAppChainInfo({
|
|
1022
|
+
autoActive: autoActiveChain,
|
|
1023
|
+
accessType: 'cardano',
|
|
1024
|
+
defaultChain: networkKey,
|
|
1025
|
+
url
|
|
1026
|
+
});
|
|
1027
|
+
networkKey = (chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.slug) || 'cardano';
|
|
1028
|
+
const cardanoApi = this.chainService.getCardanoApi(networkKey);
|
|
1029
|
+
const networkAddress = reformatAddress(address, chainInfo !== null && chainInfo !== void 0 && chainInfo.isTestnet ? 0 : 1);
|
|
1030
|
+
const balances = await cardanoApi.getBalanceMap(networkAddress);
|
|
1031
|
+
return convertAssetToValue(balances);
|
|
1032
|
+
}
|
|
1033
|
+
async cardanoSignData(id, url, params, currentAddress) {
|
|
1034
|
+
const {
|
|
1035
|
+
address: addressHex,
|
|
1036
|
+
payload
|
|
1037
|
+
} = params;
|
|
1038
|
+
const address = convertCardanoHexToBech32(addressHex);
|
|
1039
|
+
const payloadValidation = {
|
|
1040
|
+
address,
|
|
1041
|
+
type: 'cardano',
|
|
1042
|
+
payloadAfterValidated: payload,
|
|
1043
|
+
errors: [],
|
|
1044
|
+
networkKey: ''
|
|
1045
|
+
};
|
|
1046
|
+
const validationSteps = [validationAuthMiddleware, validationCardanoSignDataMiddleware];
|
|
1047
|
+
const result = await generateValidationProcess(this, url, payloadValidation, validationSteps);
|
|
1048
|
+
if (!isSameAddress(address, currentAddress)) {
|
|
1049
|
+
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED);
|
|
1050
|
+
}
|
|
1051
|
+
const errorsFormated = convertErrorFormat(result.errors);
|
|
1052
|
+
const payloadAfterValidated = {
|
|
1053
|
+
...result.payloadAfterValidated,
|
|
1054
|
+
errors: errorsFormated,
|
|
1055
|
+
id
|
|
1056
|
+
};
|
|
1057
|
+
return this.requestService.addConfirmationCardano(id, url, 'cardanoSignatureRequest', payloadAfterValidated, {}).then(({
|
|
1058
|
+
isApproved,
|
|
1059
|
+
payload
|
|
1060
|
+
}) => {
|
|
1061
|
+
if (isApproved) {
|
|
1062
|
+
if (payload) {
|
|
1063
|
+
return payload;
|
|
1064
|
+
} else {
|
|
1065
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Not found signature'));
|
|
1066
|
+
}
|
|
1067
|
+
} else {
|
|
1068
|
+
throw new CardanoProviderError(CardanoProviderErrorType.SIGN_DATA_DECLINED);
|
|
1069
|
+
}
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
// Todo: Add validate for this method
|
|
1074
|
+
async cardanoSignTx(id, url, param, currentAddress) {
|
|
1075
|
+
const {
|
|
1076
|
+
partialSign,
|
|
1077
|
+
tx: txHex
|
|
1078
|
+
} = param;
|
|
1079
|
+
const tx = CardanoWasm.Transaction.from_hex(txHex);
|
|
1080
|
+
const inputs = tx.body().inputs();
|
|
1081
|
+
const outputs = tx.body().outputs();
|
|
1082
|
+
const estimateCardanoFee = tx.body().fee().to_str();
|
|
1083
|
+
const authInfoMap = await this.getAuthList();
|
|
1084
|
+
const authInfo = authInfoMap[stripUrl(url)];
|
|
1085
|
+
if (!authInfo) {
|
|
1086
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, t('Not found auth info'));
|
|
1087
|
+
}
|
|
1088
|
+
let requireKeyHashes = [];
|
|
1089
|
+
let networkKey = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
|
|
1090
|
+
let autoActiveChain = false;
|
|
1091
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
1092
|
+
autoActiveChain = true;
|
|
1093
|
+
}
|
|
1094
|
+
const currentEvmNetwork = this.requestService.getDAppChainInfo({
|
|
1095
|
+
autoActive: autoActiveChain,
|
|
1096
|
+
accessType: 'cardano',
|
|
1097
|
+
defaultChain: networkKey,
|
|
1098
|
+
url
|
|
1099
|
+
});
|
|
1100
|
+
networkKey = (currentEvmNetwork === null || currentEvmNetwork === void 0 ? void 0 : currentEvmNetwork.slug) || 'cardano';
|
|
1101
|
+
const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
|
|
1102
|
+
const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
|
|
1103
|
+
inputs.to_js_value().forEach(input => {
|
|
1104
|
+
const availableUtxo = allUtxos.find(utxo => {
|
|
1105
|
+
const txIn = utxo.input();
|
|
1106
|
+
return txIn.transaction_id().to_hex() === input.transaction_id && txIn.index() === input.index;
|
|
1107
|
+
});
|
|
1108
|
+
if (availableUtxo) {
|
|
1109
|
+
var _availableUtxo$output, _availableUtxo$output2;
|
|
1110
|
+
const keyHash = (_availableUtxo$output = availableUtxo.output().address().payment_cred()) === null || _availableUtxo$output === void 0 ? void 0 : (_availableUtxo$output2 = _availableUtxo$output.to_keyhash()) === null || _availableUtxo$output2 === void 0 ? void 0 : _availableUtxo$output2.to_hex();
|
|
1111
|
+
if (keyHash) {
|
|
1112
|
+
requireKeyHashes.push(keyHash);
|
|
1113
|
+
}
|
|
1114
|
+
outputTransactionUnSpend.add(availableUtxo.output());
|
|
1115
|
+
}
|
|
1116
|
+
});
|
|
1117
|
+
const addressInputMap = getBalanceAddressMap(outputTransactionUnSpend);
|
|
1118
|
+
const addressOutputMap = getBalanceAddressMap(outputs);
|
|
1119
|
+
const addressInputAmountMap = {};
|
|
1120
|
+
const addressOutputAmountMap = {};
|
|
1121
|
+
let transactionValue = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
1122
|
+
for (const address in addressInputMap) {
|
|
1123
|
+
var _addressOutputMap$add;
|
|
1124
|
+
const output = (_addressOutputMap$add = addressOutputMap[address]) !== null && _addressOutputMap$add !== void 0 ? _addressOutputMap$add : CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
1125
|
+
const input = addressInputMap[address];
|
|
1126
|
+
const amount = input.checked_sub(output);
|
|
1127
|
+
if (amount.is_zero()) {
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1130
|
+
addressInputAmountMap[address] = {
|
|
1131
|
+
values: convertValueToAsset(input)
|
|
1132
|
+
};
|
|
1133
|
+
addressOutputAmountMap[address] = {
|
|
1134
|
+
values: convertValueToAsset(output)
|
|
1135
|
+
};
|
|
1136
|
+
if (isSameAddress(currentAddress, address)) {
|
|
1137
|
+
transactionValue = transactionValue.checked_add(amount);
|
|
1138
|
+
addressInputAmountMap[address].isOwner = true;
|
|
1139
|
+
addressOutputAmountMap[address].isOwner = true;
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
for (const address in addressOutputMap) {
|
|
1143
|
+
if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
|
|
1144
|
+
addressOutputAmountMap[address] = {
|
|
1145
|
+
values: convertValueToAsset(addressOutputMap[address]),
|
|
1146
|
+
isRecipient: true
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
transactionValue = transactionValue.checked_sub(CardanoWasm.Value.new(tx.body().fee()));
|
|
1151
|
+
const transactionBody = tx.body();
|
|
1152
|
+
const getSpecificUtxo = this.chainService.getSpecificUtxo.bind(this);
|
|
1153
|
+
requireKeyHashes.push(...extractKeyHashFromCertificate(transactionBody.certs()));
|
|
1154
|
+
requireKeyHashes.push(...extractKeyHashesFromWithdrawals(transactionBody.withdrawals()));
|
|
1155
|
+
requireKeyHashes.push(...extractKeyHashesFromRequiredSigners(transactionBody.required_signers()));
|
|
1156
|
+
requireKeyHashes.push(...(await extractKeyHashesFromCollaterals(transactionBody.collateral(), getSpecificUtxo(networkKey))));
|
|
1157
|
+
requireKeyHashes.push(...extractKeyHashesFromScripts(tx.witness_set().native_scripts()));
|
|
1158
|
+
requireKeyHashes = [...new Set(requireKeyHashes)];
|
|
1159
|
+
const addressRequireKeyTypes = [];
|
|
1160
|
+
const keyHashAddressMap = {};
|
|
1161
|
+
const pair = keyring.getPair(currentAddress);
|
|
1162
|
+
if (pair) {
|
|
1163
|
+
const publicKey = CardanoWasm.Bip32PublicKey.from_bytes(pair.publicKey);
|
|
1164
|
+
const paymentPubKey = publicKey.derive(0).derive(0).to_raw_key().hash().to_hex();
|
|
1165
|
+
const stakePubKey = publicKey.derive(2).derive(0).to_raw_key().hash().to_hex();
|
|
1166
|
+
keyHashAddressMap[paymentPubKey] = 'payment';
|
|
1167
|
+
keyHashAddressMap[stakePubKey] = 'stake';
|
|
1168
|
+
} else {
|
|
1169
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST);
|
|
1170
|
+
}
|
|
1171
|
+
const needForeignKeyHash = requireKeyHashes.some(key => {
|
|
1172
|
+
const ownKeyHash = keyHashAddressMap[key];
|
|
1173
|
+
if (ownKeyHash) {
|
|
1174
|
+
addressRequireKeyTypes.push(ownKeyHash);
|
|
1175
|
+
return false;
|
|
1176
|
+
}
|
|
1177
|
+
return true;
|
|
1178
|
+
});
|
|
1179
|
+
const needOwnerKeyHash = requireKeyHashes.some(key => {
|
|
1180
|
+
const ownKeyHash = keyHashAddressMap[key];
|
|
1181
|
+
if (ownKeyHash) {
|
|
1182
|
+
addressRequireKeyTypes.push(ownKeyHash);
|
|
1183
|
+
return true;
|
|
1184
|
+
}
|
|
1185
|
+
return false;
|
|
1186
|
+
});
|
|
1187
|
+
if (!needOwnerKeyHash) {
|
|
1188
|
+
throw new CardanoProviderError(CardanoProviderErrorType.PROOF_GENERATION_FAILED, t('Not found owner key hash'));
|
|
1189
|
+
}
|
|
1190
|
+
if (needForeignKeyHash && !partialSign) {
|
|
1191
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, 'Not support foreign key hash yet');
|
|
1192
|
+
}
|
|
1193
|
+
const result = {
|
|
1194
|
+
id,
|
|
1195
|
+
txInputs: addressInputAmountMap,
|
|
1196
|
+
txOutputs: addressOutputAmountMap,
|
|
1197
|
+
addressRequireKeyTypes,
|
|
1198
|
+
value: convertValueToAsset(transactionValue),
|
|
1199
|
+
estimateCardanoFee,
|
|
1200
|
+
from: currentAddress,
|
|
1201
|
+
cardanoPayload: txHex,
|
|
1202
|
+
networkKey
|
|
1203
|
+
};
|
|
1204
|
+
return this.requestService.addConfirmationCardano(id, url, 'cardanoSignTransactionRequest', result, {}).then(({
|
|
1205
|
+
isApproved,
|
|
1206
|
+
payload
|
|
1207
|
+
}) => {
|
|
1208
|
+
if (isApproved) {
|
|
1209
|
+
if (payload) {
|
|
1210
|
+
return payload;
|
|
1211
|
+
} else {
|
|
1212
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Not found signature'));
|
|
1213
|
+
}
|
|
1214
|
+
} else {
|
|
1215
|
+
throw new CardanoProviderError(CardanoProviderErrorType.SIGN_TRANSACTION_DECLINED);
|
|
1216
|
+
}
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
async cardanoSubmitTx(id, url, txHex) {
|
|
1220
|
+
const currentNetwork = this.requestService.getDAppChainInfo({
|
|
1221
|
+
autoActive: true,
|
|
1222
|
+
accessType: 'cardano',
|
|
1223
|
+
url
|
|
1224
|
+
});
|
|
1225
|
+
const networkKey = (currentNetwork === null || currentNetwork === void 0 ? void 0 : currentNetwork.slug) || 'cardano_preproduction';
|
|
1226
|
+
const cardanoApi = this.chainService.getCardanoApi(networkKey);
|
|
1227
|
+
return await cardanoApi.sendCardanoTxReturnHash(txHex);
|
|
1228
|
+
}
|
|
1010
1229
|
getConfirmationsQueueSubject() {
|
|
1011
1230
|
return this.requestService.confirmationsQueueSubject;
|
|
1012
1231
|
}
|