@subwallet/extension-base 1.3.36-0 → 1.3.38-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 +7 -0
- package/background/types.d.ts +2 -1
- package/cjs/core/logic-validation/request.js +62 -13
- package/cjs/koni/background/handlers/Extension.js +168 -108
- package/cjs/koni/background/handlers/State.js +18 -17
- package/cjs/koni/background/handlers/Tabs.js +38 -5
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/cardano/cips/cip30.js +21 -1
- package/cjs/page/cardano/index.js +5 -5
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -1
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +4 -3
- package/cjs/services/request-service/helper/index.js +19 -17
- package/cjs/services/swap-service/handler/base-handler.js +4 -2
- package/cjs/services/swap-service/handler/uniswap-handler.js +122 -57
- package/cjs/services/swap-service/index.js +1 -1
- package/cjs/utils/cardano.js +10 -2
- package/core/logic-validation/request.d.ts +1 -0
- package/core/logic-validation/request.js +63 -15
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +61 -2
- package/koni/background/handlers/State.js +20 -19
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +38 -5
- package/package.json +11 -11
- package/packageInfo.js +1 -1
- package/page/cardano/cips/cip30.d.ts +31 -17
- package/page/cardano/cips/cip30.js +17 -1
- package/page/cardano/index.d.ts +20 -4
- package/page/cardano/index.js +5 -5
- package/services/chain-service/types.d.ts +1 -1
- package/services/request-service/handler/AuthRequestHandler.js +4 -1
- package/services/request-service/handler/CardanoRequestHandler.js +4 -3
- package/services/request-service/helper/index.js +19 -17
- package/services/swap-service/handler/base-handler.js +4 -2
- package/services/swap-service/handler/uniswap-handler.d.ts +1 -1
- package/services/swap-service/handler/uniswap-handler.js +99 -34
- package/services/swap-service/index.js +1 -1
- package/types/service-base.d.ts +1 -0
- package/utils/cardano.d.ts +2 -0
- package/utils/cardano.js +7 -0
|
@@ -8,7 +8,7 @@ import { withErrorLog } from '@subwallet/extension-base/background/handlers/help
|
|
|
8
8
|
import { isSubscriptionRunning, unsubscribe } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
9
9
|
import { APIItemState, CardanoProviderErrorType, ChainType, EvmProviderErrorType, ExternalRequestPromiseStatus, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
10
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';
|
|
11
|
+
import { convertErrorFormat, generateValidationProcess, validationAuthCardanoMiddleware, validationAuthMiddleware, validationAuthWCMiddleware, validationCardanoSignDataMiddleware, validationConnectMiddleware, validationEvmDataTransactionMiddleware, validationEvmSignMessageMiddleware } from '@subwallet/extension-base/core/logic-validation';
|
|
12
12
|
import { BalanceService } from '@subwallet/extension-base/services/balance-service';
|
|
13
13
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
14
14
|
import BuyService from '@subwallet/extension-base/services/buy-service';
|
|
@@ -41,7 +41,7 @@ import WalletConnectService from '@subwallet/extension-base/services/wallet-conn
|
|
|
41
41
|
import { SWStorage } from '@subwallet/extension-base/storage';
|
|
42
42
|
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
43
43
|
import { addLazy, isManifestV3, isSameAddress, reformatAddress, stripUrl, targetIsWeb } from '@subwallet/extension-base/utils';
|
|
44
|
-
import { convertCardanoHexToBech32 } from '@subwallet/extension-base/utils/cardano';
|
|
44
|
+
import { convertCardanoHexToBech32, validateAddressNetwork } from '@subwallet/extension-base/utils/cardano';
|
|
45
45
|
import { createPromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
46
46
|
import subwalletApiSdk from '@subwallet/subwallet-api-sdk';
|
|
47
47
|
import { keyring } from '@subwallet/ui-keyring';
|
|
@@ -1046,14 +1046,12 @@ export default class KoniState {
|
|
|
1046
1046
|
errors: [],
|
|
1047
1047
|
networkKey: ''
|
|
1048
1048
|
};
|
|
1049
|
-
const validationSteps = [
|
|
1049
|
+
const validationSteps = [validationAuthCardanoMiddleware, validationCardanoSignDataMiddleware];
|
|
1050
1050
|
const result = await generateValidationProcess(this, url, payloadValidation, validationSteps);
|
|
1051
|
-
if (!isSameAddress(address, currentAddress)) {
|
|
1052
|
-
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED);
|
|
1053
|
-
}
|
|
1054
1051
|
const errorsFormated = convertErrorFormat(result.errors);
|
|
1055
1052
|
const payloadAfterValidated = {
|
|
1056
1053
|
...result.payloadAfterValidated,
|
|
1054
|
+
currentAddress,
|
|
1057
1055
|
errors: errorsFormated,
|
|
1058
1056
|
id
|
|
1059
1057
|
};
|
|
@@ -1094,13 +1092,13 @@ export default class KoniState {
|
|
|
1094
1092
|
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
1095
1093
|
autoActiveChain = true;
|
|
1096
1094
|
}
|
|
1097
|
-
const
|
|
1095
|
+
const currentCardanoNetwork = this.requestService.getDAppChainInfo({
|
|
1098
1096
|
autoActive: autoActiveChain,
|
|
1099
1097
|
accessType: 'cardano',
|
|
1100
1098
|
defaultChain: networkKey,
|
|
1101
1099
|
url
|
|
1102
1100
|
});
|
|
1103
|
-
networkKey = (
|
|
1101
|
+
networkKey = (currentCardanoNetwork === null || currentCardanoNetwork === void 0 ? void 0 : currentCardanoNetwork.slug) || 'cardano';
|
|
1104
1102
|
const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
|
|
1105
1103
|
const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
|
|
1106
1104
|
inputs.to_js_value().forEach(input => {
|
|
@@ -1137,12 +1135,23 @@ export default class KoniState {
|
|
|
1137
1135
|
values: convertValueToAsset(output)
|
|
1138
1136
|
};
|
|
1139
1137
|
if (isSameAddress(currentAddress, address)) {
|
|
1138
|
+
if (!validateAddressNetwork(address, currentCardanoNetwork)) {
|
|
1139
|
+
throw new CardanoProviderError(CardanoProviderErrorType.ACCOUNT_CHANGED, t('Current network is changed'));
|
|
1140
|
+
}
|
|
1140
1141
|
transactionValue = transactionValue.checked_add(amount);
|
|
1141
1142
|
addressInputAmountMap[address].isOwner = true;
|
|
1142
1143
|
addressOutputAmountMap[address].isOwner = true;
|
|
1143
1144
|
}
|
|
1145
|
+
|
|
1146
|
+
// Check if address is valid with current network
|
|
1147
|
+
if (!validateAddressNetwork(address, currentCardanoNetwork)) {
|
|
1148
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Current network is not match with input address'));
|
|
1149
|
+
}
|
|
1144
1150
|
}
|
|
1145
1151
|
for (const address in addressOutputMap) {
|
|
1152
|
+
if (!validateAddressNetwork(address, currentCardanoNetwork)) {
|
|
1153
|
+
throw new CardanoProviderError(CardanoProviderErrorType.INVALID_REQUEST, t('Current network is not match with output address'));
|
|
1154
|
+
}
|
|
1146
1155
|
if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
|
|
1147
1156
|
addressOutputAmountMap[address] = {
|
|
1148
1157
|
values: convertValueToAsset(addressOutputMap[address]),
|
|
@@ -1150,7 +1159,6 @@ export default class KoniState {
|
|
|
1150
1159
|
};
|
|
1151
1160
|
}
|
|
1152
1161
|
}
|
|
1153
|
-
transactionValue = transactionValue.checked_sub(CardanoWasm.Value.new(tx.body().fee()));
|
|
1154
1162
|
const transactionBody = tx.body();
|
|
1155
1163
|
const getSpecificUtxo = this.chainService.getSpecificUtxo.bind(this);
|
|
1156
1164
|
requireKeyHashes.push(...extractKeyHashFromCertificate(transactionBody.certs()));
|
|
@@ -1163,9 +1171,8 @@ export default class KoniState {
|
|
|
1163
1171
|
const keyHashAddressMap = {};
|
|
1164
1172
|
const pair = keyring.getPair(currentAddress);
|
|
1165
1173
|
if (pair) {
|
|
1166
|
-
const
|
|
1167
|
-
const
|
|
1168
|
-
const stakePubKey = publicKey.derive(2).derive(0).to_raw_key().hash().to_hex();
|
|
1174
|
+
const paymentPubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.paymentPubKey).to_raw_key().hash().to_hex();
|
|
1175
|
+
const stakePubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.stakePubKey).to_raw_key().hash().to_hex();
|
|
1169
1176
|
keyHashAddressMap[paymentPubKey] = 'payment';
|
|
1170
1177
|
keyHashAddressMap[stakePubKey] = 'stake';
|
|
1171
1178
|
} else {
|
|
@@ -1250,13 +1257,7 @@ export default class KoniState {
|
|
|
1250
1257
|
async onMV3Update() {
|
|
1251
1258
|
const migrationStatus = await SWStorage.instance.getItem('mv3_migration');
|
|
1252
1259
|
if (!migrationStatus || migrationStatus !== 'done') {
|
|
1253
|
-
if (isManifestV3) {
|
|
1254
|
-
// Open migration tab
|
|
1255
|
-
const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
|
|
1256
|
-
await openPopup(url);
|
|
1257
|
-
|
|
1258
|
-
// migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
|
|
1259
|
-
} else {
|
|
1260
|
+
if (!isManifestV3) {
|
|
1260
1261
|
this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
|
|
1261
1262
|
}
|
|
1262
1263
|
}
|
|
@@ -53,6 +53,7 @@ export default class KoniTabs {
|
|
|
53
53
|
private cardanoGetAccountList;
|
|
54
54
|
private cardanoGetAccountBalance;
|
|
55
55
|
private cardanoGetChangeAddress;
|
|
56
|
+
private cardanoGetRewardAddress;
|
|
56
57
|
private cardanoGetCurrentNetworkId;
|
|
57
58
|
private cardanoGetUtxo;
|
|
58
59
|
private cardanoGetCollateral;
|
|
@@ -27,6 +27,7 @@ import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
|
27
27
|
function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTypes) {
|
|
28
28
|
const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
|
|
29
29
|
const authTypeFilter = ({
|
|
30
|
+
json,
|
|
30
31
|
type
|
|
31
32
|
}) => {
|
|
32
33
|
if (accountAuthTypes) {
|
|
@@ -39,10 +40,19 @@ function transformAccountsV2(accounts, anyType = false, authInfo, accountAuthTyp
|
|
|
39
40
|
ton: TonKeypairTypes,
|
|
40
41
|
cardano: CardanoKeypairTypes
|
|
41
42
|
};
|
|
42
|
-
|
|
43
|
+
const isValidTypes = accountAuthTypes.some(authType => {
|
|
43
44
|
var _validTypes$authType;
|
|
44
45
|
return (_validTypes$authType = validTypes[authType]) === null || _validTypes$authType === void 0 ? void 0 : _validTypes$authType.includes(type);
|
|
45
46
|
});
|
|
47
|
+
if (!isValidTypes) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// This condition ensures that the resulting UTXOs from the user's transaction are not sent to addresses the wallet cannot manage.
|
|
52
|
+
if (type === 'cardano' && json.meta.isReadOnly) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
46
56
|
} else {
|
|
47
57
|
return true;
|
|
48
58
|
}
|
|
@@ -1099,8 +1109,8 @@ export default class KoniTabs {
|
|
|
1099
1109
|
this.#koniState.setAuthorize(authList);
|
|
1100
1110
|
}
|
|
1101
1111
|
return accountList.map(address => {
|
|
1102
|
-
const
|
|
1103
|
-
const addressChainFormat = reformatAddress(address, +
|
|
1112
|
+
const isMainnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1113
|
+
const addressChainFormat = reformatAddress(address, +isMainnet);
|
|
1104
1114
|
return convertCardanoAddressToHex(addressChainFormat);
|
|
1105
1115
|
});
|
|
1106
1116
|
}
|
|
@@ -1128,10 +1138,31 @@ export default class KoniTabs {
|
|
|
1128
1138
|
address,
|
|
1129
1139
|
network
|
|
1130
1140
|
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1131
|
-
const
|
|
1132
|
-
const addressChainFormat = reformatAddress(address, +
|
|
1141
|
+
const isMainnet = network !== 'cardano_preproduction';
|
|
1142
|
+
const addressChainFormat = reformatAddress(address, +isMainnet);
|
|
1133
1143
|
return convertCardanoAddressToHex(addressChainFormat);
|
|
1134
1144
|
}
|
|
1145
|
+
async cardanoGetRewardAddress(id, url) {
|
|
1146
|
+
const authList = await this.#koniState.getAuthList();
|
|
1147
|
+
const urlStripped = stripUrl(url);
|
|
1148
|
+
const authInfo = authList[urlStripped];
|
|
1149
|
+
if (!authInfo || !authInfo.isAllowedMap) {
|
|
1150
|
+
throw new CardanoProviderError(CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1151
|
+
}
|
|
1152
|
+
const accountList = await this.getCurrentAccount(url, 'cardano');
|
|
1153
|
+
const currentCardanoAccount = authInfo.currentAccount;
|
|
1154
|
+
if (currentCardanoAccount !== accountList[0]) {
|
|
1155
|
+
authList[urlStripped].currentAccount = accountList[0];
|
|
1156
|
+
this.#koniState.setAuthorize(authList);
|
|
1157
|
+
}
|
|
1158
|
+
return accountList.map(address => {
|
|
1159
|
+
const pair = keyring.getPair(address);
|
|
1160
|
+
const rewardAddress = pair.cardano.rewardAddress;
|
|
1161
|
+
const isTestnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1162
|
+
const addressChainFormat = reformatAddress(rewardAddress, +isTestnet);
|
|
1163
|
+
return convertCardanoAddressToHex(addressChainFormat);
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1135
1166
|
async cardanoGetCurrentNetworkId(id, url) {
|
|
1136
1167
|
let currentChain;
|
|
1137
1168
|
let autoActiveChain = false;
|
|
@@ -1312,6 +1343,8 @@ export default class KoniTabs {
|
|
|
1312
1343
|
return await this.cardanoGetAccountBalance(id, url);
|
|
1313
1344
|
case 'cardano(account.get.change.address)':
|
|
1314
1345
|
return await this.cardanoGetChangeAddress(id, url);
|
|
1346
|
+
case 'cardano(account.get.reward.address)':
|
|
1347
|
+
return await this.cardanoGetRewardAddress(id, url);
|
|
1315
1348
|
case 'cardano(account.get.collateral)':
|
|
1316
1349
|
return await this.cardanoGetCollateral(id, url, request);
|
|
1317
1350
|
case 'cardano(account.get.utxos)':
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.38-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2710,20 +2710,20 @@
|
|
|
2710
2710
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2711
2711
|
"@substrate/connect": "^0.8.9",
|
|
2712
2712
|
"@subwallet/chain-list": "0.2.104",
|
|
2713
|
-
"@subwallet/extension-base": "^1.3.
|
|
2714
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2715
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2716
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2717
|
-
"@subwallet/keyring": "^0.1.
|
|
2718
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2719
|
-
"@subwallet/ui-keyring": "^0.1.
|
|
2713
|
+
"@subwallet/extension-base": "^1.3.38-0",
|
|
2714
|
+
"@subwallet/extension-chains": "^1.3.38-0",
|
|
2715
|
+
"@subwallet/extension-dapp": "^1.3.38-0",
|
|
2716
|
+
"@subwallet/extension-inject": "^1.3.38-0",
|
|
2717
|
+
"@subwallet/keyring": "^0.1.12",
|
|
2718
|
+
"@subwallet/subwallet-api-sdk": "^1.3.38-0",
|
|
2719
|
+
"@subwallet/ui-keyring": "^0.1.12",
|
|
2720
2720
|
"@ton/core": "^0.56.3",
|
|
2721
2721
|
"@ton/crypto": "^3.2.0",
|
|
2722
2722
|
"@ton/ton": "^15.0.0",
|
|
2723
2723
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
|
2724
|
-
"@walletconnect/sign-client": "^2.
|
|
2725
|
-
"@walletconnect/types": "^2.
|
|
2726
|
-
"@walletconnect/utils": "^2.
|
|
2724
|
+
"@walletconnect/sign-client": "^2.20.2",
|
|
2725
|
+
"@walletconnect/types": "^2.20.2",
|
|
2726
|
+
"@walletconnect/utils": "^2.20.2",
|
|
2727
2727
|
"avail-js-sdk": "^0.2.12",
|
|
2728
2728
|
"axios": "^1.6.2",
|
|
2729
2729
|
"bignumber.js": "^9.1.1",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.38-0'
|
|
11
11
|
};
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
import { CardanoPaginate, Cbor } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import { SendRequest } from '@subwallet/extension-base/page/types';
|
|
3
3
|
export declare class CIP30Api {
|
|
4
|
-
private sendMessage;
|
|
4
|
+
private readonly sendMessage;
|
|
5
5
|
constructor(sendMessage: SendRequest);
|
|
6
|
-
getExtension
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
private getExtension;
|
|
7
|
+
private getNetworkId;
|
|
8
|
+
private getCollateral;
|
|
9
|
+
private getUtxos;
|
|
10
|
+
private getUsedAddresses;
|
|
11
|
+
private getChangeAddress;
|
|
12
|
+
private getUnusedAddresses;
|
|
13
|
+
private getRewardAddresses;
|
|
14
|
+
private signTx;
|
|
15
|
+
private signData;
|
|
16
|
+
private submitTx;
|
|
17
|
+
private getBalance;
|
|
18
|
+
get apis(): {
|
|
19
|
+
getExtension: () => {
|
|
20
|
+
cip: number;
|
|
21
|
+
}[];
|
|
22
|
+
getNetworkId: () => Promise<number>;
|
|
23
|
+
getCollateral: (payload: {
|
|
24
|
+
amount: Cbor;
|
|
25
|
+
}) => Promise<string[] | null>;
|
|
26
|
+
getUtxos: (amount?: Cbor, paginate?: CardanoPaginate) => Promise<string[] | null>;
|
|
27
|
+
getUsedAddresses: () => Promise<string[]>;
|
|
28
|
+
getChangeAddress: () => Promise<string>;
|
|
29
|
+
getUnusedAddresses: () => Promise<string[]>;
|
|
30
|
+
getRewardAddresses: () => Promise<string[]>;
|
|
31
|
+
signTx: (tx: Cbor, partialSign?: boolean) => Promise<string>;
|
|
32
|
+
signData: (address: string, payload: string) => Promise<import("@subwallet/extension-base/background/KoniTypes").ResponseCardanoSignData>;
|
|
33
|
+
submitTx: (tx: Cbor) => Promise<string>;
|
|
34
|
+
getBalance: () => Promise<string>;
|
|
35
|
+
};
|
|
22
36
|
}
|
|
@@ -32,7 +32,7 @@ export class CIP30Api {
|
|
|
32
32
|
return new Promise(resolve => resolve([]));
|
|
33
33
|
}
|
|
34
34
|
async getRewardAddresses() {
|
|
35
|
-
return
|
|
35
|
+
return await this.sendMessage('cardano(account.get.reward.address)');
|
|
36
36
|
}
|
|
37
37
|
async signTx(tx, partialSign = false) {
|
|
38
38
|
return await this.sendMessage('cardano(transaction.sign)', {
|
|
@@ -52,4 +52,20 @@ export class CIP30Api {
|
|
|
52
52
|
async getBalance() {
|
|
53
53
|
return await this.sendMessage('cardano(account.get.balance)');
|
|
54
54
|
}
|
|
55
|
+
get apis() {
|
|
56
|
+
return {
|
|
57
|
+
getExtension: () => this.getExtension(),
|
|
58
|
+
getNetworkId: () => this.getNetworkId(),
|
|
59
|
+
getCollateral: payload => this.getCollateral(payload),
|
|
60
|
+
getUtxos: (amount, paginate) => this.getUtxos(amount, paginate),
|
|
61
|
+
getUsedAddresses: () => this.getUsedAddresses(),
|
|
62
|
+
getChangeAddress: () => this.getChangeAddress(),
|
|
63
|
+
getUnusedAddresses: () => this.getUnusedAddresses(),
|
|
64
|
+
getRewardAddresses: () => this.getRewardAddresses(),
|
|
65
|
+
signTx: (tx, partialSign = false) => this.signTx(tx, partialSign),
|
|
66
|
+
signData: (address, payload) => this.signData(address, payload),
|
|
67
|
+
submitTx: tx => this.submitTx(tx),
|
|
68
|
+
getBalance: () => this.getBalance()
|
|
69
|
+
};
|
|
70
|
+
}
|
|
55
71
|
}
|
package/page/cardano/index.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import type { CardanoExtensionCIP, CardanoProvider } from '@subwallet/extension-inject/types';
|
|
2
|
-
import { CIP30Api } from '@subwallet/extension-base/page/cardano/cips';
|
|
3
2
|
import { SendRequest } from '@subwallet/extension-base/page/types';
|
|
4
3
|
export default class SubWalletCardanoProvider implements CardanoProvider {
|
|
5
4
|
readonly apiVersion: string;
|
|
6
5
|
readonly icon: string;
|
|
7
6
|
readonly name: string;
|
|
8
7
|
readonly supportedExtensions: CardanoExtensionCIP[];
|
|
9
|
-
|
|
8
|
+
private readonly sendMessage;
|
|
10
9
|
constructor(sendMessage: SendRequest);
|
|
11
|
-
enable()
|
|
12
|
-
|
|
10
|
+
enable: () => Promise<Readonly<{
|
|
11
|
+
getExtension: () => {
|
|
12
|
+
cip: number;
|
|
13
|
+
}[];
|
|
14
|
+
getNetworkId: () => Promise<number>;
|
|
15
|
+
getCollateral: (payload: {
|
|
16
|
+
amount: string;
|
|
17
|
+
}) => Promise<string[] | null>;
|
|
18
|
+
getUtxos: (amount?: string | undefined, paginate?: import("../../background/KoniTypes").CardanoPaginate | undefined) => Promise<string[] | null>;
|
|
19
|
+
getUsedAddresses: () => Promise<string[]>;
|
|
20
|
+
getChangeAddress: () => Promise<string>;
|
|
21
|
+
getUnusedAddresses: () => Promise<string[]>;
|
|
22
|
+
getRewardAddresses: () => Promise<string[]>;
|
|
23
|
+
signTx: (tx: string, partialSign?: boolean) => Promise<string>;
|
|
24
|
+
signData: (address: string, payload: string) => Promise<import("../../background/KoniTypes").ResponseCardanoSignData>;
|
|
25
|
+
submitTx: (tx: string) => Promise<string>;
|
|
26
|
+
getBalance: () => Promise<string>;
|
|
27
|
+
}>>;
|
|
28
|
+
isEnable: () => Promise<boolean>;
|
|
13
29
|
}
|
package/page/cardano/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export default class SubWalletCardanoProvider {
|
|
|
14
14
|
this.icon = WALLET_ICON;
|
|
15
15
|
this.sendMessage = sendMessage;
|
|
16
16
|
}
|
|
17
|
-
async
|
|
17
|
+
enable = async () => {
|
|
18
18
|
const isEnabled = await this.sendMessage('pub(authorize.tabV2)', {
|
|
19
19
|
origin,
|
|
20
20
|
accountAuthTypes: ['cardano']
|
|
@@ -23,12 +23,12 @@ export default class SubWalletCardanoProvider {
|
|
|
23
23
|
throw new Error('Access to the wallet is denied');
|
|
24
24
|
}
|
|
25
25
|
const CIP30 = new CIP30Api(this.sendMessage);
|
|
26
|
-
return Object.freeze(CIP30);
|
|
27
|
-
}
|
|
28
|
-
async
|
|
26
|
+
return Object.freeze(CIP30.apis);
|
|
27
|
+
};
|
|
28
|
+
isEnable = async () => {
|
|
29
29
|
const accountList = await this.sendMessage('pub(accounts.list)', {
|
|
30
30
|
accountAuthType: 'cardano'
|
|
31
31
|
});
|
|
32
32
|
return accountList.length > 0;
|
|
33
|
-
}
|
|
33
|
+
};
|
|
34
34
|
}
|
|
@@ -15,8 +15,8 @@ import { ChainProperties, ChainType, RuntimeVersion } from '@polkadot/types/inte
|
|
|
15
15
|
import { AnyJson, Registry } from '@polkadot/types/types';
|
|
16
16
|
export interface _DataMap {
|
|
17
17
|
chainInfoMap: Record<string, _ChainInfo>;
|
|
18
|
-
chainStateMap: Record<string, _ChainState>;
|
|
19
18
|
assetRegistry: Record<string, _ChainAsset>;
|
|
19
|
+
chainStateMap: Record<string, _ChainState>;
|
|
20
20
|
assetRefMap: Record<string, _AssetRef>;
|
|
21
21
|
}
|
|
22
22
|
export declare enum _ChainConnectionStatus {
|
|
@@ -260,7 +260,10 @@ export default class AuthRequestHandler {
|
|
|
260
260
|
origin,
|
|
261
261
|
url,
|
|
262
262
|
accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
|
|
263
|
-
currentNetworkMap: existed ?
|
|
263
|
+
currentNetworkMap: existed ? {
|
|
264
|
+
...defaultNetworkMap,
|
|
265
|
+
...existed.currentNetworkMap
|
|
266
|
+
} : defaultNetworkMap
|
|
264
267
|
};
|
|
265
268
|
this.setAuthorize(authorizeList, () => {
|
|
266
269
|
cb();
|
|
@@ -132,14 +132,15 @@ export default class CardanoRequestHandler {
|
|
|
132
132
|
}
|
|
133
133
|
signMessage(confirmation) {
|
|
134
134
|
const {
|
|
135
|
-
address,
|
|
135
|
+
address: addressToSign,
|
|
136
|
+
currentAddress,
|
|
136
137
|
payload
|
|
137
138
|
} = confirmation.payload;
|
|
138
|
-
const pair = keyring.getPair(
|
|
139
|
+
const pair = keyring.getPair(currentAddress);
|
|
139
140
|
if (pair.isLocked) {
|
|
140
141
|
keyring.unlockPair(pair.address);
|
|
141
142
|
}
|
|
142
|
-
return pair.cardano.signMessage(payload,
|
|
143
|
+
return pair.cardano.signMessage(payload, addressToSign);
|
|
143
144
|
}
|
|
144
145
|
signTransactionCardano(confirmation) {
|
|
145
146
|
// alibaba
|
|
@@ -46,25 +46,27 @@ export const extractMetadata = store => {
|
|
|
46
46
|
export const convertAssetToValue = amount => {
|
|
47
47
|
const value = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
48
48
|
const multiAsset = CardanoWasm.MultiAsset.new();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
if (amount !== null && amount !== void 0 && amount.length) {
|
|
50
|
+
for (const item of amount) {
|
|
51
|
+
if (item.unit === 'lovelace') {
|
|
52
|
+
value.set_coin(CardanoWasm.BigNum.from_str(item.quantity));
|
|
53
|
+
} else {
|
|
54
|
+
const policyIdHex = item.unit.slice(0, 56);
|
|
55
|
+
const assetNameHex = item.unit.slice(56);
|
|
56
|
+
const scriptHash = CardanoWasm.ScriptHash.from_bytes(Buffer.from(policyIdHex, 'hex'));
|
|
57
|
+
const assetName = CardanoWasm.AssetName.new(Buffer.from(assetNameHex, 'hex'));
|
|
58
|
+
const quantity = CardanoWasm.BigNum.from_str(item.quantity);
|
|
59
|
+
let assets = multiAsset.get(scriptHash);
|
|
60
|
+
if (!assets) {
|
|
61
|
+
assets = CardanoWasm.Assets.new();
|
|
62
|
+
}
|
|
63
|
+
assets.insert(assetName, quantity);
|
|
64
|
+
multiAsset.insert(scriptHash, assets);
|
|
61
65
|
}
|
|
62
|
-
assets.insert(assetName, quantity);
|
|
63
|
-
multiAsset.insert(scriptHash, assets);
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
if (multiAsset.len() > 0) {
|
|
68
|
+
value.set_multiasset(multiAsset);
|
|
69
|
+
}
|
|
68
70
|
}
|
|
69
71
|
return value;
|
|
70
72
|
};
|
|
@@ -165,6 +165,8 @@ export class SwapBaseHandler {
|
|
|
165
165
|
if (needEditAmount) {
|
|
166
166
|
bnSendingValue = BigN(selectedQuote.toAmount).multipliedBy(DEFAULT_EXCESS_AMOUNT_WEIGHT); // need to round
|
|
167
167
|
} else {
|
|
168
|
+
// todo: remove
|
|
169
|
+
console.log('The code cannot run into here, if it runs into here, pls ask dev to check');
|
|
168
170
|
bnSendingValue = BigN(selectedQuote.toAmount);
|
|
169
171
|
}
|
|
170
172
|
}
|
|
@@ -365,8 +367,8 @@ export class SwapBaseHandler {
|
|
|
365
367
|
if (recipient) {
|
|
366
368
|
const isEvmAddress = isEthereumAddress(recipient);
|
|
367
369
|
const isEvmDestChain = _isChainEvmCompatible(swapToChain);
|
|
368
|
-
if (isEvmAddress
|
|
369
|
-
// todo: update
|
|
370
|
+
if (isEvmAddress !== isEvmDestChain) {
|
|
371
|
+
// todo: update condition if support swap chain # EVM or Substrate
|
|
370
372
|
return [new TransactionError(SwapErrorType.INVALID_RECIPIENT)];
|
|
371
373
|
}
|
|
372
374
|
}
|
|
@@ -71,7 +71,7 @@ export declare class UniswapHandler implements SwapBaseInterface {
|
|
|
71
71
|
generateOptimalProcessV2(params: OptimalSwapPathParamsV2): Promise<CommonOptimalSwapPath>;
|
|
72
72
|
getApprovalStep(params: OptimalSwapPathParamsV2, stepIndex: number): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
73
73
|
getApproveSwap(params: OptimalSwapPathParamsV2): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
74
|
-
getApproveBridge(params: OptimalSwapPathParamsV2): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
74
|
+
getApproveBridge(params: OptimalSwapPathParamsV2, isBridgeFirst: boolean): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
75
75
|
getPermitStep(params: OptimalSwapPathParamsV2, stepIndex: number): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
76
76
|
getSubmitStep(params: OptimalSwapPathParamsV2, stepIndex: number): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|
|
77
77
|
getBridgeStep(params: OptimalSwapPathParamsV2, stepIndex: number): Promise<[BaseStepDetail, CommonStepFeeInfo] | undefined>;
|