@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
|
@@ -1068,14 +1068,12 @@ class KoniState {
|
|
|
1068
1068
|
errors: [],
|
|
1069
1069
|
networkKey: ''
|
|
1070
1070
|
};
|
|
1071
|
-
const validationSteps = [_logicValidation.
|
|
1071
|
+
const validationSteps = [_logicValidation.validationAuthCardanoMiddleware, _logicValidation.validationCardanoSignDataMiddleware];
|
|
1072
1072
|
const result = await (0, _logicValidation.generateValidationProcess)(this, url, payloadValidation, validationSteps);
|
|
1073
|
-
if (!(0, _utils3.isSameAddress)(address, currentAddress)) {
|
|
1074
|
-
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED);
|
|
1075
|
-
}
|
|
1076
1073
|
const errorsFormated = (0, _logicValidation.convertErrorFormat)(result.errors);
|
|
1077
1074
|
const payloadAfterValidated = {
|
|
1078
1075
|
...result.payloadAfterValidated,
|
|
1076
|
+
currentAddress,
|
|
1079
1077
|
errors: errorsFormated,
|
|
1080
1078
|
id
|
|
1081
1079
|
};
|
|
@@ -1117,13 +1115,13 @@ class KoniState {
|
|
|
1117
1115
|
if (authInfo !== null && authInfo !== void 0 && authInfo.isAllowed) {
|
|
1118
1116
|
autoActiveChain = true;
|
|
1119
1117
|
}
|
|
1120
|
-
const
|
|
1118
|
+
const currentCardanoNetwork = this.requestService.getDAppChainInfo({
|
|
1121
1119
|
autoActive: autoActiveChain,
|
|
1122
1120
|
accessType: 'cardano',
|
|
1123
1121
|
defaultChain: networkKey,
|
|
1124
1122
|
url
|
|
1125
1123
|
});
|
|
1126
|
-
networkKey = (
|
|
1124
|
+
networkKey = (currentCardanoNetwork === null || currentCardanoNetwork === void 0 ? void 0 : currentCardanoNetwork.slug) || 'cardano';
|
|
1127
1125
|
const allUtxos = await this.chainService.getUtxosByAddress(currentAddress, networkKey);
|
|
1128
1126
|
const outputTransactionUnSpend = CardanoWasm.TransactionOutputs.new();
|
|
1129
1127
|
inputs.to_js_value().forEach(input => {
|
|
@@ -1160,12 +1158,23 @@ class KoniState {
|
|
|
1160
1158
|
values: (0, _helper.convertValueToAsset)(output)
|
|
1161
1159
|
};
|
|
1162
1160
|
if ((0, _utils3.isSameAddress)(currentAddress, address)) {
|
|
1161
|
+
if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
|
|
1162
|
+
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.ACCOUNT_CHANGED, (0, _i18next.t)('Current network is changed'));
|
|
1163
|
+
}
|
|
1163
1164
|
transactionValue = transactionValue.checked_add(amount);
|
|
1164
1165
|
addressInputAmountMap[address].isOwner = true;
|
|
1165
1166
|
addressOutputAmountMap[address].isOwner = true;
|
|
1166
1167
|
}
|
|
1168
|
+
|
|
1169
|
+
// Check if address is valid with current network
|
|
1170
|
+
if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
|
|
1171
|
+
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, (0, _i18next.t)('Current network is not match with input address'));
|
|
1172
|
+
}
|
|
1167
1173
|
}
|
|
1168
1174
|
for (const address in addressOutputMap) {
|
|
1175
|
+
if (!(0, _cardano.validateAddressNetwork)(address, currentCardanoNetwork)) {
|
|
1176
|
+
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.INVALID_REQUEST, (0, _i18next.t)('Current network is not match with output address'));
|
|
1177
|
+
}
|
|
1169
1178
|
if (!addressInputAmountMap[address] && !addressOutputMap[address].is_zero()) {
|
|
1170
1179
|
addressOutputAmountMap[address] = {
|
|
1171
1180
|
values: (0, _helper.convertValueToAsset)(addressOutputMap[address]),
|
|
@@ -1173,7 +1182,6 @@ class KoniState {
|
|
|
1173
1182
|
};
|
|
1174
1183
|
}
|
|
1175
1184
|
}
|
|
1176
|
-
transactionValue = transactionValue.checked_sub(CardanoWasm.Value.new(tx.body().fee()));
|
|
1177
1185
|
const transactionBody = tx.body();
|
|
1178
1186
|
const getSpecificUtxo = this.chainService.getSpecificUtxo.bind(this);
|
|
1179
1187
|
requireKeyHashes.push(...(0, _helper.extractKeyHashFromCertificate)(transactionBody.certs()));
|
|
@@ -1186,9 +1194,8 @@ class KoniState {
|
|
|
1186
1194
|
const keyHashAddressMap = {};
|
|
1187
1195
|
const pair = _uiKeyring.keyring.getPair(currentAddress);
|
|
1188
1196
|
if (pair) {
|
|
1189
|
-
const
|
|
1190
|
-
const
|
|
1191
|
-
const stakePubKey = publicKey.derive(2).derive(0).to_raw_key().hash().to_hex();
|
|
1197
|
+
const paymentPubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.paymentPubKey).to_raw_key().hash().to_hex();
|
|
1198
|
+
const stakePubKey = CardanoWasm.Bip32PublicKey.from_hex(pair.cardano.stakePubKey).to_raw_key().hash().to_hex();
|
|
1192
1199
|
keyHashAddressMap[paymentPubKey] = 'payment';
|
|
1193
1200
|
keyHashAddressMap[stakePubKey] = 'stake';
|
|
1194
1201
|
} else {
|
|
@@ -1274,13 +1281,7 @@ class KoniState {
|
|
|
1274
1281
|
async onMV3Update() {
|
|
1275
1282
|
const migrationStatus = await _storage.SWStorage.instance.getItem('mv3_migration');
|
|
1276
1283
|
if (!migrationStatus || migrationStatus !== 'done') {
|
|
1277
|
-
if (_utils3.isManifestV3) {
|
|
1278
|
-
// Open migration tab
|
|
1279
|
-
const url = `${chrome.runtime.getURL('index.html')}#/mv3-migration`;
|
|
1280
|
-
await (0, _PopupHandler.openPopup)(url);
|
|
1281
|
-
|
|
1282
|
-
// migrateMV3LocalStorage will be called when user open migration tab with data from localStorage on frontend
|
|
1283
|
-
} else {
|
|
1284
|
+
if (!_utils3.isManifestV3) {
|
|
1284
1285
|
this.migrateMV3LocalStorage(JSON.stringify(self.localStorage)).catch(console.error);
|
|
1285
1286
|
}
|
|
1286
1287
|
}
|
|
@@ -40,6 +40,7 @@ function transformAccountsV2(accounts) {
|
|
|
40
40
|
const accountSelected = authInfo ? authInfo.isAllowed ? Object.keys(authInfo.isAllowedMap).filter(address => authInfo.isAllowedMap[address]) : [] : [];
|
|
41
41
|
const authTypeFilter = _ref => {
|
|
42
42
|
let {
|
|
43
|
+
json,
|
|
43
44
|
type
|
|
44
45
|
} = _ref;
|
|
45
46
|
if (accountAuthTypes) {
|
|
@@ -52,10 +53,19 @@ function transformAccountsV2(accounts) {
|
|
|
52
53
|
ton: _types3.TonKeypairTypes,
|
|
53
54
|
cardano: _types3.CardanoKeypairTypes
|
|
54
55
|
};
|
|
55
|
-
|
|
56
|
+
const isValidTypes = accountAuthTypes.some(authType => {
|
|
56
57
|
var _validTypes$authType;
|
|
57
58
|
return (_validTypes$authType = validTypes[authType]) === null || _validTypes$authType === void 0 ? void 0 : _validTypes$authType.includes(type);
|
|
58
59
|
});
|
|
60
|
+
if (!isValidTypes) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// This condition ensures that the resulting UTXOs from the user's transaction are not sent to addresses the wallet cannot manage.
|
|
65
|
+
if (type === 'cardano' && json.meta.isReadOnly) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
59
69
|
} else {
|
|
60
70
|
return true;
|
|
61
71
|
}
|
|
@@ -1143,8 +1153,8 @@ class KoniTabs {
|
|
|
1143
1153
|
this.#koniState.setAuthorize(authList);
|
|
1144
1154
|
}
|
|
1145
1155
|
return accountList.map(address => {
|
|
1146
|
-
const
|
|
1147
|
-
const addressChainFormat = (0, _utils2.reformatAddress)(address, +
|
|
1156
|
+
const isMainnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1157
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(address, +isMainnet);
|
|
1148
1158
|
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1149
1159
|
});
|
|
1150
1160
|
}
|
|
@@ -1172,10 +1182,31 @@ class KoniTabs {
|
|
|
1172
1182
|
address,
|
|
1173
1183
|
network
|
|
1174
1184
|
} = await this.getCurrentInformationCardanoDapp(url);
|
|
1175
|
-
const
|
|
1176
|
-
const addressChainFormat = (0, _utils2.reformatAddress)(address, +
|
|
1185
|
+
const isMainnet = network !== 'cardano_preproduction';
|
|
1186
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(address, +isMainnet);
|
|
1177
1187
|
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1178
1188
|
}
|
|
1189
|
+
async cardanoGetRewardAddress(id, url) {
|
|
1190
|
+
const authList = await this.#koniState.getAuthList();
|
|
1191
|
+
const urlStripped = (0, _utils2.stripUrl)(url);
|
|
1192
|
+
const authInfo = authList[urlStripped];
|
|
1193
|
+
if (!authInfo || !authInfo.isAllowedMap) {
|
|
1194
|
+
throw new _CardanoProviderError.CardanoProviderError(_KoniTypes.CardanoProviderErrorType.REFUSED_REQUEST, 'You need to connect to the wallet first');
|
|
1195
|
+
}
|
|
1196
|
+
const accountList = await this.getCurrentAccount(url, 'cardano');
|
|
1197
|
+
const currentCardanoAccount = authInfo.currentAccount;
|
|
1198
|
+
if (currentCardanoAccount !== accountList[0]) {
|
|
1199
|
+
authList[urlStripped].currentAccount = accountList[0];
|
|
1200
|
+
this.#koniState.setAuthorize(authList);
|
|
1201
|
+
}
|
|
1202
|
+
return accountList.map(address => {
|
|
1203
|
+
const pair = _uiKeyring.keyring.getPair(address);
|
|
1204
|
+
const rewardAddress = pair.cardano.rewardAddress;
|
|
1205
|
+
const isTestnet = (authInfo === null || authInfo === void 0 ? void 0 : authInfo.currentNetworkMap.cardano) !== 'cardano_preproduction';
|
|
1206
|
+
const addressChainFormat = (0, _utils2.reformatAddress)(rewardAddress, +isTestnet);
|
|
1207
|
+
return (0, _utils2.convertCardanoAddressToHex)(addressChainFormat);
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1179
1210
|
async cardanoGetCurrentNetworkId(id, url) {
|
|
1180
1211
|
let currentChain;
|
|
1181
1212
|
let autoActiveChain = false;
|
|
@@ -1356,6 +1387,8 @@ class KoniTabs {
|
|
|
1356
1387
|
return await this.cardanoGetAccountBalance(id, url);
|
|
1357
1388
|
case 'cardano(account.get.change.address)':
|
|
1358
1389
|
return await this.cardanoGetChangeAddress(id, url);
|
|
1390
|
+
case 'cardano(account.get.reward.address)':
|
|
1391
|
+
return await this.cardanoGetRewardAddress(id, url);
|
|
1359
1392
|
case 'cardano(account.get.collateral)':
|
|
1360
1393
|
return await this.cardanoGetCollateral(id, url, request);
|
|
1361
1394
|
case 'cardano(account.get.utxos)':
|
package/cjs/packageInfo.js
CHANGED
|
@@ -38,7 +38,7 @@ class CIP30Api {
|
|
|
38
38
|
return new Promise(resolve => resolve([]));
|
|
39
39
|
}
|
|
40
40
|
async getRewardAddresses() {
|
|
41
|
-
return
|
|
41
|
+
return await this.sendMessage('cardano(account.get.reward.address)');
|
|
42
42
|
}
|
|
43
43
|
async signTx(tx) {
|
|
44
44
|
let partialSign = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
@@ -59,5 +59,25 @@ class CIP30Api {
|
|
|
59
59
|
async getBalance() {
|
|
60
60
|
return await this.sendMessage('cardano(account.get.balance)');
|
|
61
61
|
}
|
|
62
|
+
get apis() {
|
|
63
|
+
var _this = this;
|
|
64
|
+
return {
|
|
65
|
+
getExtension: () => this.getExtension(),
|
|
66
|
+
getNetworkId: () => this.getNetworkId(),
|
|
67
|
+
getCollateral: payload => this.getCollateral(payload),
|
|
68
|
+
getUtxos: (amount, paginate) => this.getUtxos(amount, paginate),
|
|
69
|
+
getUsedAddresses: () => this.getUsedAddresses(),
|
|
70
|
+
getChangeAddress: () => this.getChangeAddress(),
|
|
71
|
+
getUnusedAddresses: () => this.getUnusedAddresses(),
|
|
72
|
+
getRewardAddresses: () => this.getRewardAddresses(),
|
|
73
|
+
signTx: function (tx) {
|
|
74
|
+
let partialSign = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
75
|
+
return _this.signTx(tx, partialSign);
|
|
76
|
+
},
|
|
77
|
+
signData: (address, payload) => this.signData(address, payload),
|
|
78
|
+
submitTx: tx => this.submitTx(tx),
|
|
79
|
+
getBalance: () => this.getBalance()
|
|
80
|
+
};
|
|
81
|
+
}
|
|
62
82
|
}
|
|
63
83
|
exports.CIP30Api = CIP30Api;
|
|
@@ -20,7 +20,7 @@ class SubWalletCardanoProvider {
|
|
|
20
20
|
this.icon = WALLET_ICON;
|
|
21
21
|
this.sendMessage = sendMessage;
|
|
22
22
|
}
|
|
23
|
-
async
|
|
23
|
+
enable = async () => {
|
|
24
24
|
const isEnabled = await this.sendMessage('pub(authorize.tabV2)', {
|
|
25
25
|
origin,
|
|
26
26
|
accountAuthTypes: ['cardano']
|
|
@@ -29,13 +29,13 @@ class SubWalletCardanoProvider {
|
|
|
29
29
|
throw new Error('Access to the wallet is denied');
|
|
30
30
|
}
|
|
31
31
|
const CIP30 = new _cips.CIP30Api(this.sendMessage);
|
|
32
|
-
return Object.freeze(CIP30);
|
|
33
|
-
}
|
|
34
|
-
async
|
|
32
|
+
return Object.freeze(CIP30.apis);
|
|
33
|
+
};
|
|
34
|
+
isEnable = async () => {
|
|
35
35
|
const accountList = await this.sendMessage('pub(accounts.list)', {
|
|
36
36
|
accountAuthType: 'cardano'
|
|
37
37
|
});
|
|
38
38
|
return accountList.length > 0;
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
exports.default = SubWalletCardanoProvider;
|
|
@@ -273,7 +273,10 @@ class AuthRequestHandler {
|
|
|
273
273
|
origin,
|
|
274
274
|
url,
|
|
275
275
|
accountAuthTypes: [...new Set([...accountAuthTypes, ...((existed === null || existed === void 0 ? void 0 : existed.accountAuthTypes) || [])])],
|
|
276
|
-
currentNetworkMap: existed ?
|
|
276
|
+
currentNetworkMap: existed ? {
|
|
277
|
+
...defaultNetworkMap,
|
|
278
|
+
...existed.currentNetworkMap
|
|
279
|
+
} : defaultNetworkMap
|
|
277
280
|
};
|
|
278
281
|
this.setAuthorize(authorizeList, () => {
|
|
279
282
|
cb();
|
|
@@ -140,14 +140,15 @@ class CardanoRequestHandler {
|
|
|
140
140
|
}
|
|
141
141
|
signMessage(confirmation) {
|
|
142
142
|
const {
|
|
143
|
-
address,
|
|
143
|
+
address: addressToSign,
|
|
144
|
+
currentAddress,
|
|
144
145
|
payload
|
|
145
146
|
} = confirmation.payload;
|
|
146
|
-
const pair = _uiKeyring.keyring.getPair(
|
|
147
|
+
const pair = _uiKeyring.keyring.getPair(currentAddress);
|
|
147
148
|
if (pair.isLocked) {
|
|
148
149
|
_uiKeyring.keyring.unlockPair(pair.address);
|
|
149
150
|
}
|
|
150
|
-
return pair.cardano.signMessage(payload,
|
|
151
|
+
return pair.cardano.signMessage(payload, addressToSign);
|
|
151
152
|
}
|
|
152
153
|
signTransactionCardano(confirmation) {
|
|
153
154
|
// alibaba
|
|
@@ -70,25 +70,27 @@ exports.extractMetadata = extractMetadata;
|
|
|
70
70
|
const convertAssetToValue = amount => {
|
|
71
71
|
const value = CardanoWasm.Value.new(CardanoWasm.BigNum.from_str('0'));
|
|
72
72
|
const multiAsset = CardanoWasm.MultiAsset.new();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
73
|
+
if (amount !== null && amount !== void 0 && amount.length) {
|
|
74
|
+
for (const item of amount) {
|
|
75
|
+
if (item.unit === 'lovelace') {
|
|
76
|
+
value.set_coin(CardanoWasm.BigNum.from_str(item.quantity));
|
|
77
|
+
} else {
|
|
78
|
+
const policyIdHex = item.unit.slice(0, 56);
|
|
79
|
+
const assetNameHex = item.unit.slice(56);
|
|
80
|
+
const scriptHash = CardanoWasm.ScriptHash.from_bytes(Buffer.from(policyIdHex, 'hex'));
|
|
81
|
+
const assetName = CardanoWasm.AssetName.new(Buffer.from(assetNameHex, 'hex'));
|
|
82
|
+
const quantity = CardanoWasm.BigNum.from_str(item.quantity);
|
|
83
|
+
let assets = multiAsset.get(scriptHash);
|
|
84
|
+
if (!assets) {
|
|
85
|
+
assets = CardanoWasm.Assets.new();
|
|
86
|
+
}
|
|
87
|
+
assets.insert(assetName, quantity);
|
|
88
|
+
multiAsset.insert(scriptHash, assets);
|
|
85
89
|
}
|
|
86
|
-
assets.insert(assetName, quantity);
|
|
87
|
-
multiAsset.insert(scriptHash, assets);
|
|
88
90
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
if (multiAsset.len() > 0) {
|
|
92
|
+
value.set_multiasset(multiAsset);
|
|
93
|
+
}
|
|
92
94
|
}
|
|
93
95
|
return value;
|
|
94
96
|
};
|
|
@@ -173,6 +173,8 @@ class SwapBaseHandler {
|
|
|
173
173
|
if (needEditAmount) {
|
|
174
174
|
bnSendingValue = (0, _bignumber.default)(selectedQuote.toAmount).multipliedBy(_utils3.DEFAULT_EXCESS_AMOUNT_WEIGHT); // need to round
|
|
175
175
|
} else {
|
|
176
|
+
// todo: remove
|
|
177
|
+
console.log('The code cannot run into here, if it runs into here, pls ask dev to check');
|
|
176
178
|
bnSendingValue = (0, _bignumber.default)(selectedQuote.toAmount);
|
|
177
179
|
}
|
|
178
180
|
}
|
|
@@ -373,8 +375,8 @@ class SwapBaseHandler {
|
|
|
373
375
|
if (recipient) {
|
|
374
376
|
const isEvmAddress = (0, _utilCrypto.isEthereumAddress)(recipient);
|
|
375
377
|
const isEvmDestChain = (0, _utils2._isChainEvmCompatible)(swapToChain);
|
|
376
|
-
if (isEvmAddress
|
|
377
|
-
// todo: update
|
|
378
|
+
if (isEvmAddress !== isEvmDestChain) {
|
|
379
|
+
// todo: update condition if support swap chain # EVM or Substrate
|
|
378
380
|
return [new _TransactionError.TransactionError(_swap.SwapErrorType.INVALID_RECIPIENT)];
|
|
379
381
|
}
|
|
380
382
|
}
|