@subwallet/extension-base 1.3.31-1 → 1.3.33-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 +94 -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/environment.js +4 -2
- 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 +141 -107
- package/cjs/koni/background/handlers/State.js +232 -6
- 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/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/price-service/coingecko.js +22 -3
- package/cjs/services/price-service/index.js +75 -2
- 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 +16 -4
- package/cjs/utils/price.js +28 -0
- package/constants/environment.d.ts +1 -0
- package/constants/environment.js +2 -1
- 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.d.ts +2 -0
- package/koni/background/handlers/Extension.js +32 -2
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +228 -6
- package/koni/background/handlers/Tabs.d.ts +11 -1
- package/koni/background/handlers/Tabs.js +242 -19
- package/package.json +67 -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/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/price-service/coingecko.d.ts +2 -1
- package/services/price-service/coingecko.js +19 -1
- package/services/price-service/index.d.ts +11 -1
- package/services/price-service/index.js +78 -5
- 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 +2 -1
- package/utils/index.js +2 -1
- package/utils/price.d.ts +3 -0
- package/utils/price.js +20 -0
- 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
|
@@ -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;
|
|
@@ -90,6 +90,8 @@ export default class KoniExtension {
|
|
|
90
90
|
private subscribeAssetSetting;
|
|
91
91
|
private updateAssetSetting;
|
|
92
92
|
private getPrice;
|
|
93
|
+
private getHistoryTokenPrice;
|
|
94
|
+
private subscribeCurrentTokenPrice;
|
|
93
95
|
private setPriceCurrency;
|
|
94
96
|
private subscribePrice;
|
|
95
97
|
private getBalance;
|
|
@@ -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
|
}, []);
|
|
@@ -869,6 +874,27 @@ export default class KoniExtension {
|
|
|
869
874
|
async getPrice() {
|
|
870
875
|
return this.#koniState.priceService.getPrice();
|
|
871
876
|
}
|
|
877
|
+
async getHistoryTokenPrice({
|
|
878
|
+
priceId,
|
|
879
|
+
timeframe
|
|
880
|
+
}) {
|
|
881
|
+
return this.#koniState.priceService.getHistoryTokenPriceData(priceId, timeframe);
|
|
882
|
+
}
|
|
883
|
+
subscribeCurrentTokenPrice(priceId, id, port) {
|
|
884
|
+
const cb = createSubscription(id, port);
|
|
885
|
+
const {
|
|
886
|
+
currentPrice,
|
|
887
|
+
unsubscribe
|
|
888
|
+
} = this.#koniState.priceService.subscribeCurrentTokenPrice(priceId, cb);
|
|
889
|
+
this.createUnsubscriptionHandle(id, unsubscribe);
|
|
890
|
+
port.onDisconnect.addListener(() => {
|
|
891
|
+
this.cancelSubscription(id);
|
|
892
|
+
});
|
|
893
|
+
return {
|
|
894
|
+
id,
|
|
895
|
+
price: currentPrice
|
|
896
|
+
};
|
|
897
|
+
}
|
|
872
898
|
async setPriceCurrency({
|
|
873
899
|
currency
|
|
874
900
|
}) {
|
|
@@ -4243,6 +4269,10 @@ export default class KoniExtension {
|
|
|
4243
4269
|
return await this.getPrice();
|
|
4244
4270
|
case 'pri(price.getSubscription)':
|
|
4245
4271
|
return await this.subscribePrice(id, port);
|
|
4272
|
+
case 'pri(price.getHistory)':
|
|
4273
|
+
return await this.getHistoryTokenPrice(request);
|
|
4274
|
+
case 'pri(price.subscribeCurrentTokenPrice)':
|
|
4275
|
+
return this.subscribeCurrentTokenPrice(request, id, port);
|
|
4246
4276
|
case 'pri(settings.savePriceCurrency)':
|
|
4247
4277
|
return await this.setPriceCurrency(request);
|
|
4248
4278
|
case 'pri(balance.getBalance)':
|
|
@@ -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';
|
|
8
|
-
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';
|
|
9
|
+
import { APIItemState, CardanoProviderErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
10
|
+
import { BACKEND_API_URL, BACKEND_PRICE_HISTORY_URL, MANTA_PAY_BALANCE_INTERVAL, REMIND_EXPORT_ACCOUNT } from '@subwallet/extension-base/constants';
|
|
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';
|
|
@@ -85,7 +89,10 @@ export default class KoniState {
|
|
|
85
89
|
waitStarting = null;
|
|
86
90
|
constructor(providers = {}) {
|
|
87
91
|
// Init subwallet api sdk
|
|
88
|
-
subwalletApiSdk.init(
|
|
92
|
+
subwalletApiSdk.init({
|
|
93
|
+
url: BACKEND_API_URL,
|
|
94
|
+
priceHistoryUrl: BACKEND_PRICE_HISTORY_URL
|
|
95
|
+
});
|
|
89
96
|
this.providers = providers;
|
|
90
97
|
this.eventService = new EventService();
|
|
91
98
|
this.dbService = new DatabaseService(this.eventService);
|
|
@@ -430,7 +437,7 @@ export default class KoniState {
|
|
|
430
437
|
if (chainInfo && !_isChainEnabled(chainState)) {
|
|
431
438
|
await this.enableChainWithPriorityAssets(networkKey);
|
|
432
439
|
}
|
|
433
|
-
authUrls[shortenUrl].
|
|
440
|
+
authUrls[shortenUrl].currentNetworkMap.evm = networkKey;
|
|
434
441
|
this.setAuthorize(authUrls);
|
|
435
442
|
} else {
|
|
436
443
|
throw new EvmProviderError(EvmProviderErrorType.INTERNAL_ERROR, t('Not found {{shortenUrl}} in auth list', {
|
|
@@ -877,6 +884,7 @@ export default class KoniState {
|
|
|
877
884
|
}
|
|
878
885
|
const payloadValidation = {
|
|
879
886
|
address,
|
|
887
|
+
type: 'evm',
|
|
880
888
|
payloadAfterValidated: payload,
|
|
881
889
|
method,
|
|
882
890
|
errors: [],
|
|
@@ -930,6 +938,7 @@ export default class KoniState {
|
|
|
930
938
|
async evmSendTransaction(id, url, transactionParams, networkKeyInit, topic) {
|
|
931
939
|
const payloadValidation = {
|
|
932
940
|
errors: [],
|
|
941
|
+
type: 'evm',
|
|
933
942
|
networkKey: networkKeyInit || '',
|
|
934
943
|
payloadAfterValidated: transactionParams,
|
|
935
944
|
address: transactionParams.from
|
|
@@ -1007,6 +1016,219 @@ export default class KoniState {
|
|
|
1007
1016
|
});
|
|
1008
1017
|
});
|
|
1009
1018
|
}
|
|
1019
|
+
async cardanoGetBalance(id, url, address) {
|
|
1020
|
+
const authInfoMap = await this.getAuthList();
|
|
1021
|
+
const authInfo = authInfoMap[stripUrl(url)];
|
|
1022
|
+
let networkKey = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
|
|
1023
|
+
const autoActiveChain = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.isAllowed) || false;
|
|
1024
|
+
const chainInfo = this.requestService.getDAppChainInfo({
|
|
1025
|
+
autoActive: autoActiveChain,
|
|
1026
|
+
accessType: 'cardano',
|
|
1027
|
+
defaultChain: networkKey,
|
|
1028
|
+
url
|
|
1029
|
+
});
|
|
1030
|
+
networkKey = (chainInfo === null || chainInfo === void 0 ? void 0 : chainInfo.slug) || 'cardano';
|
|
1031
|
+
const cardanoApi = this.chainService.getCardanoApi(networkKey);
|
|
1032
|
+
const networkAddress = reformatAddress(address, chainInfo !== null && chainInfo !== void 0 && chainInfo.isTestnet ? 0 : 1);
|
|
1033
|
+
const balances = await cardanoApi.getBalanceMap(networkAddress);
|
|
1034
|
+
return convertAssetToValue(balances);
|
|
1035
|
+
}
|
|
1036
|
+
async cardanoSignData(id, url, params, currentAddress) {
|
|
1037
|
+
const {
|
|
1038
|
+
address: addressHex,
|
|
1039
|
+
payload
|
|
1040
|
+
} = params;
|
|
1041
|
+
const address = convertCardanoHexToBech32(addressHex);
|
|
1042
|
+
const payloadValidation = {
|
|
1043
|
+
address,
|
|
1044
|
+
type: 'cardano',
|
|
1045
|
+
payloadAfterValidated: payload,
|
|
1046
|
+
errors: [],
|
|
1047
|
+
networkKey: ''
|
|
1048
|
+
};
|
|
1049
|
+
const validationSteps = [validationAuthMiddleware, validationCardanoSignDataMiddleware];
|
|
1050
|
+
const result = await generateValidationProcess(this, url, payloadValidation, validationSteps);
|
|
1051
|
+
if (!isSameAddress(address, currentAddress)) {
|
|
1052
|
+
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED);
|
|
1053
|
+
}
|
|
1054
|
+
const errorsFormated = convertErrorFormat(result.errors);
|
|
1055
|
+
const payloadAfterValidated = {
|
|
1056
|
+
...result.payloadAfterValidated,
|
|
1057
|
+
errors: errorsFormated,
|
|
1058
|
+
id
|
|
1059
|
+
};
|
|
1060
|
+
return this.requestService.addConfirmationCardano(id, url, 'cardanoSignatureRequest', payloadAfterValidated, {}).then(({
|
|
1061
|
+
isApproved,
|
|
1062
|
+
payload
|
|
1063
|
+
}) => {
|
|
1064
|
+
if (isApproved) {
|
|
1065
|
+
if (payload) {
|
|
1066
|
+
return payload;
|
|
1067
|
+
} else {
|
|
1068
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Not found signature'));
|
|
1069
|
+
}
|
|
1070
|
+
} else {
|
|
1071
|
+
throw new CardanoProviderError(CardanoProviderErrorType.SIGN_DATA_DECLINED);
|
|
1072
|
+
}
|
|
1073
|
+
});
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
// Todo: Add validate for this method
|
|
1077
|
+
async cardanoSignTx(id, url, param, currentAddress) {
|
|
1078
|
+
const {
|
|
1079
|
+
partialSign,
|
|
1080
|
+
tx: txHex
|
|
1081
|
+
} = param;
|
|
1082
|
+
const tx = CardanoWasm.Transaction.from_hex(txHex);
|
|
1083
|
+
const inputs = tx.body().inputs();
|
|
1084
|
+
const outputs = tx.body().outputs();
|
|
1085
|
+
const estimateCardanoFee = tx.body().fee().to_str();
|
|
1086
|
+
const authInfoMap = await this.getAuthList();
|
|
1087
|
+
const authInfo = authInfoMap[stripUrl(url)];
|
|
1088
|
+
if (!authInfo) {
|
|
1089
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, t('Not found auth info'));
|
|
1090
|
+
}
|
|
1091
|
+
let requireKeyHashes = [];
|
|
1092
|
+
let networkKey = authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano;
|
|
1093
|
+
let autoActiveChain = false;
|
|
1094
|
+
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
1095
|
+
autoActiveChain = true;
|
|
1096
|
+
}
|
|
1097
|
+
const currentEvmNetwork = this.requestService.getDAppChainInfo({
|
|
1098
|
+
autoActive: autoActiveChain,
|
|
1099
|
+
accessType: 'cardano',
|
|
1100
|
+
defaultChain: networkKey,
|
|
1101
|
+
url
|
|
1102
|
+
});
|
|
1103
|
+
networkKey = (currentEvmNetwork === null || currentEvmNetwork === void 0 ? void 0 : currentEvmNetwork.slug) || 'cardano';
|
|
1104
|
+
const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
|
|
1105
|
+
const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
|
|
1106
|
+
inputs.to_js_value().forEach(input => {
|
|
1107
|
+
const availableUtxo = allUtxos.find(utxo => {
|
|
1108
|
+
const txIn = utxo.input();
|
|
1109
|
+
return txIn.transaction_id().to_hex() === input.transaction_id && txIn.index() === input.index;
|
|
1110
|
+
});
|
|
1111
|
+
if (availableUtxo) {
|
|
1112
|
+
var _availableUtxo$output, _availableUtxo$output2;
|
|
1113
|
+
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();
|
|
1114
|
+
if (keyHash) {
|
|
1115
|
+
requireKeyHashes.push(keyHash);
|
|
1116
|
+
}
|
|
1117
|
+
outputTransactionUnSpend.add(availableUtxo.output());
|
|
1118
|
+
}
|
|
1119
|
+
});
|
|
1120
|
+
const addressInputMap = getBalanceAddressMap(outputTransactionUnSpend);
|
|
1121
|
+
const addressOutputMap = getBalanceAddressMap(outputs);
|
|
1122
|
+
const addressInputAmountMap = {};
|
|
1123
|
+
const addressOutputAmountMap = {};
|
|
1124
|
+
let transactionValue = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
1125
|
+
for (const address in addressInputMap) {
|
|
1126
|
+
var _addressOutputMap$add;
|
|
1127
|
+
const output = (_addressOutputMap$add = addressOutputMap[address]) !== null && _addressOutputMap$add !== void 0 ? _addressOutputMap$add : CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
1128
|
+
const input = addressInputMap[address];
|
|
1129
|
+
const amount = input.checked_sub(output);
|
|
1130
|
+
if (amount.is_zero()) {
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
addressInputAmountMap[address] = {
|
|
1134
|
+
values: convertValueToAsset(input)
|
|
1135
|
+
};
|
|
1136
|
+
addressOutputAmountMap[address] = {
|
|
1137
|
+
values: convertValueToAsset(output)
|
|
1138
|
+
};
|
|
1139
|
+
if (isSameAddress(currentAddress, address)) {
|
|
1140
|
+
transactionValue = transactionValue.checked_add(amount);
|
|
1141
|
+
addressInputAmountMap[address].isOwner = true;
|
|
1142
|
+
addressOutputAmountMap[address].isOwner = true;
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
for (const address in addressOutputMap) {
|
|
1146
|
+
if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
|
|
1147
|
+
addressOutputAmountMap[address] = {
|
|
1148
|
+
values: convertValueToAsset(addressOutputMap[address]),
|
|
1149
|
+
isRecipient: true
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
transactionValue = transactionValue.checked_sub(CardanoWasm.Value.new(tx.body().fee()));
|
|
1154
|
+
const transactionBody = tx.body();
|
|
1155
|
+
const getSpecificUtxo = this.chainService.getSpecificUtxo.bind(this);
|
|
1156
|
+
requireKeyHashes.push(...extractKeyHashFromCertificate(transactionBody.certs()));
|
|
1157
|
+
requireKeyHashes.push(...extractKeyHashesFromWithdrawals(transactionBody.withdrawals()));
|
|
1158
|
+
requireKeyHashes.push(...extractKeyHashesFromRequiredSigners(transactionBody.required_signers()));
|
|
1159
|
+
requireKeyHashes.push(...(await extractKeyHashesFromCollaterals(transactionBody.collateral(), getSpecificUtxo(networkKey))));
|
|
1160
|
+
requireKeyHashes.push(...extractKeyHashesFromScripts(tx.witness_set().native_scripts()));
|
|
1161
|
+
requireKeyHashes = [...new Set(requireKeyHashes)];
|
|
1162
|
+
const addressRequireKeyTypes = [];
|
|
1163
|
+
const keyHashAddressMap = {};
|
|
1164
|
+
const pair = keyring.getPair(currentAddress);
|
|
1165
|
+
if (pair) {
|
|
1166
|
+
const publicKey = CardanoWasm.Bip32PublicKey.from_bytes(pair.publicKey);
|
|
1167
|
+
const paymentPubKey = publicKey.derive(0).derive(0).to_raw_key().hash().to_hex();
|
|
1168
|
+
const stakePubKey = publicKey.derive(2).derive(0).to_raw_key().hash().to_hex();
|
|
1169
|
+
keyHashAddressMap[paymentPubKey] = 'payment';
|
|
1170
|
+
keyHashAddressMap[stakePubKey] = 'stake';
|
|
1171
|
+
} else {
|
|
1172
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST);
|
|
1173
|
+
}
|
|
1174
|
+
const needForeignKeyHash = requireKeyHashes.some(key => {
|
|
1175
|
+
const ownKeyHash = keyHashAddressMap[key];
|
|
1176
|
+
if (ownKeyHash) {
|
|
1177
|
+
addressRequireKeyTypes.push(ownKeyHash);
|
|
1178
|
+
return false;
|
|
1179
|
+
}
|
|
1180
|
+
return true;
|
|
1181
|
+
});
|
|
1182
|
+
const needOwnerKeyHash = requireKeyHashes.some(key => {
|
|
1183
|
+
const ownKeyHash = keyHashAddressMap[key];
|
|
1184
|
+
if (ownKeyHash) {
|
|
1185
|
+
addressRequireKeyTypes.push(ownKeyHash);
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
return false;
|
|
1189
|
+
});
|
|
1190
|
+
if (!needOwnerKeyHash) {
|
|
1191
|
+
throw new CardanoProviderError(CardanoProviderErrorType.PROOF_GENERATION_FAILED, t('Not found owner key hash'));
|
|
1192
|
+
}
|
|
1193
|
+
if (needForeignKeyHash && !partialSign) {
|
|
1194
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, 'Not support foreign key hash yet');
|
|
1195
|
+
}
|
|
1196
|
+
const result = {
|
|
1197
|
+
id,
|
|
1198
|
+
txInputs: addressInputAmountMap,
|
|
1199
|
+
txOutputs: addressOutputAmountMap,
|
|
1200
|
+
addressRequireKeyTypes,
|
|
1201
|
+
value: convertValueToAsset(transactionValue),
|
|
1202
|
+
estimateCardanoFee,
|
|
1203
|
+
from: currentAddress,
|
|
1204
|
+
cardanoPayload: txHex,
|
|
1205
|
+
networkKey
|
|
1206
|
+
};
|
|
1207
|
+
return this.requestService.addConfirmationCardano(id, url, 'cardanoSignTransactionRequest', result, {}).then(({
|
|
1208
|
+
isApproved,
|
|
1209
|
+
payload
|
|
1210
|
+
}) => {
|
|
1211
|
+
if (isApproved) {
|
|
1212
|
+
if (payload) {
|
|
1213
|
+
return payload;
|
|
1214
|
+
} else {
|
|
1215
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Not found signature'));
|
|
1216
|
+
}
|
|
1217
|
+
} else {
|
|
1218
|
+
throw new CardanoProviderError(CardanoProviderErrorType.SIGN_TRANSACTION_DECLINED);
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
async cardanoSubmitTx(id, url, txHex) {
|
|
1223
|
+
const currentNetwork = this.requestService.getDAppChainInfo({
|
|
1224
|
+
autoActive: true,
|
|
1225
|
+
accessType: 'cardano',
|
|
1226
|
+
url
|
|
1227
|
+
});
|
|
1228
|
+
const networkKey = (currentNetwork === null || currentNetwork === void 0 ? void 0 : currentNetwork.slug) || 'cardano_preproduction';
|
|
1229
|
+
const cardanoApi = this.chainService.getCardanoApi(networkKey);
|
|
1230
|
+
return await cardanoApi.sendCardanoTxReturnHash(txHex);
|
|
1231
|
+
}
|
|
1010
1232
|
getConfirmationsQueueSubject() {
|
|
1011
1233
|
return this.requestService.confirmationsQueueSubject;
|
|
1012
1234
|
}
|
|
@@ -30,7 +30,7 @@ export default class KoniTabs {
|
|
|
30
30
|
private accountsSubstrateSubscribeV2;
|
|
31
31
|
private accountsUnsubscribe;
|
|
32
32
|
private authorizeV2;
|
|
33
|
-
private
|
|
33
|
+
private getCurrentAccount;
|
|
34
34
|
private getEvmState;
|
|
35
35
|
private getEvmPermission;
|
|
36
36
|
private revokePermissions;
|
|
@@ -49,5 +49,15 @@ export default class KoniTabs {
|
|
|
49
49
|
private handleEvmSend;
|
|
50
50
|
isEvmPublicRequest(type: string, request: RequestArguments): boolean;
|
|
51
51
|
addPspToken(id: string, url: string, { genesisHash, tokenInfo: input }: RequestAddPspToken): Promise<true>;
|
|
52
|
+
private getCurrentInformationCardanoDapp;
|
|
53
|
+
private cardanoGetAccountList;
|
|
54
|
+
private cardanoGetAccountBalance;
|
|
55
|
+
private cardanoGetChangeAddress;
|
|
56
|
+
private cardanoGetCurrentNetworkId;
|
|
57
|
+
private cardanoGetUtxo;
|
|
58
|
+
private cardanoGetCollateral;
|
|
59
|
+
private cardanoSignData;
|
|
60
|
+
private cardanoSignTransaction;
|
|
61
|
+
private cardanoSubmitTransaction;
|
|
52
62
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], url: string, port: chrome.runtime.Port): Promise<ResponseTypes[keyof ResponseTypes]>;
|
|
53
63
|
}
|