@subwallet/extension-base 1.2.27-0 → 1.2.29-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 -8
- package/cjs/constants/index.js +6 -3
- package/cjs/core/logic-validation/request.js +160 -23
- package/cjs/core/substrate/xcm-parser.js +16 -6
- package/cjs/koni/api/staking/bonding/utils.js +1 -0
- package/cjs/koni/background/handlers/Extension.js +3 -3
- package/cjs/koni/background/handlers/State.js +35 -66
- package/cjs/koni/background/handlers/Tabs.js +96 -23
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -13
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
- package/cjs/services/balance-service/transfer/xcm/index.js +8 -13
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/chain-service/index.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +1 -3
- package/cjs/services/earning-service/handlers/lending/interlay.js +0 -2
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +31 -25
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +1 -2
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/mkt-campaign-service/index.js +30 -6
- package/cjs/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/cjs/services/wallet-connect-service/index.js +25 -1
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/logic-validation/request.d.ts +22 -1
- package/core/logic-validation/request.js +154 -23
- package/core/substrate/xcm-parser.d.ts +3 -2
- package/core/substrate/xcm-parser.js +15 -6
- package/koni/api/staking/bonding/utils.js +1 -0
- package/koni/background/handlers/Extension.js +3 -3
- package/koni/background/handlers/State.d.ts +0 -1
- package/koni/background/handlers/State.js +19 -49
- package/koni/background/handlers/Tabs.d.ts +1 -0
- package/koni/background/handlers/Tabs.js +77 -6
- package/package.json +14 -12
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +19 -13
- package/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
- package/services/balance-service/transfer/xcm/index.js +8 -13
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +2 -1
- package/services/chain-service/index.js +1 -1
- package/services/earning-service/constants/chains.d.ts +0 -1
- package/services/earning-service/constants/chains.js +0 -1
- package/services/earning-service/handlers/lending/interlay.js +0 -2
- package/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
- package/services/earning-service/handlers/native-staking/relay-chain.js +32 -26
- package/services/earning-service/handlers/nomination-pool/index.js +1 -2
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
- package/services/migration-service/scripts/index.js +2 -2
- package/services/mkt-campaign-service/index.js +30 -6
- package/services/mkt-campaign-service/types.d.ts +2 -0
- package/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/services/swap-service/handler/hydradx-handler.js +1 -1
- package/services/wallet-connect-service/index.js +24 -1
- package/types/yield/info/chain/target.d.ts +4 -0
|
@@ -13,8 +13,8 @@ class MigrateAssetSetting extends _Base.default {
|
|
|
13
13
|
async run() {
|
|
14
14
|
try {
|
|
15
15
|
const changeSlugsMap = {
|
|
16
|
-
'
|
|
17
|
-
'
|
|
16
|
+
'polygon-NATIVE-MATIC': 'polygon-NATIVE-POL',
|
|
17
|
+
'5irechain_mainnet-NATIVE-5IRE': '5irechain_mainnet-NATIVE-5ire'
|
|
18
18
|
};
|
|
19
19
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
20
20
|
const migratedAssetSetting = {};
|
|
@@ -61,8 +61,8 @@ var _default = {
|
|
|
61
61
|
'1.1.33-01': _MigrateLedgerAccountV.default,
|
|
62
62
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
63
63
|
'1.1.46-01': _AutoEnableSomeTokens.default,
|
|
64
|
-
'1.
|
|
65
|
-
'1.
|
|
64
|
+
'1.2.28-01': _MigrateAssetSetting.default,
|
|
65
|
+
'1.2.28-02': _MigrateTransactionHistoryBySymbol.default,
|
|
66
66
|
'1.2.69-01': _MigrateRemoveGenesisHash.default,
|
|
67
67
|
'1.2.13-01': _ReloadMetadata.default,
|
|
68
68
|
'1.2.14-01': _ClearMetadataDatabase.default
|
|
@@ -247,35 +247,59 @@ class MktCampaignService {
|
|
|
247
247
|
const isValidArr = conditionBalance.map(condition => {
|
|
248
248
|
return conditionMap[JSON.stringify(condition)];
|
|
249
249
|
});
|
|
250
|
-
|
|
250
|
+
if (item.comparison_operator === 'AND') {
|
|
251
|
+
isPassValidation.push(isValidArr.every(i => i));
|
|
252
|
+
} else {
|
|
253
|
+
isPassValidation.push(isValidArr.some(i => i));
|
|
254
|
+
}
|
|
251
255
|
}
|
|
252
256
|
if (conditionEarning && conditionEarning.length) {
|
|
253
257
|
const isValidArr = conditionEarning.map(condition => {
|
|
254
258
|
return conditionMap[JSON.stringify(condition)];
|
|
255
259
|
});
|
|
256
|
-
|
|
260
|
+
if (item.comparison_operator === 'AND') {
|
|
261
|
+
isPassValidation.push(isValidArr.every(i => i));
|
|
262
|
+
} else {
|
|
263
|
+
isPassValidation.push(isValidArr.some(i => i));
|
|
264
|
+
}
|
|
257
265
|
}
|
|
258
266
|
if (conditionNft && conditionNft.length) {
|
|
259
267
|
const isValidArr = conditionNft.map(condition => {
|
|
260
268
|
return conditionMap[JSON.stringify(condition)];
|
|
261
269
|
});
|
|
262
|
-
|
|
270
|
+
if (item.comparison_operator === 'AND') {
|
|
271
|
+
isPassValidation.push(isValidArr.every(i => i));
|
|
272
|
+
} else {
|
|
273
|
+
isPassValidation.push(isValidArr.some(i => i));
|
|
274
|
+
}
|
|
263
275
|
}
|
|
264
276
|
if (conditionCrowdloan && conditionCrowdloan.length) {
|
|
265
277
|
const isValidArr = conditionCrowdloan.map(condition => {
|
|
266
278
|
return conditionMap[JSON.stringify(condition)];
|
|
267
279
|
});
|
|
268
|
-
|
|
280
|
+
if (item.comparison_operator === 'AND') {
|
|
281
|
+
isPassValidation.push(isValidArr.every(i => i));
|
|
282
|
+
} else {
|
|
283
|
+
isPassValidation.push(isValidArr.some(i => i));
|
|
284
|
+
}
|
|
269
285
|
}
|
|
270
286
|
if (conditionHasMoney && conditionHasMoney.length) {
|
|
271
287
|
const isValidArr = conditionHasMoney.map(condition => {
|
|
272
288
|
return conditionMap[JSON.stringify(condition)];
|
|
273
289
|
});
|
|
274
|
-
|
|
290
|
+
if (item.comparison_operator === 'AND') {
|
|
291
|
+
isPassValidation.push(isValidArr.every(i => i));
|
|
292
|
+
} else {
|
|
293
|
+
isPassValidation.push(isValidArr.some(i => i));
|
|
294
|
+
}
|
|
275
295
|
}
|
|
276
296
|
}
|
|
277
297
|
if (isPassValidation && isPassValidation.length) {
|
|
278
|
-
|
|
298
|
+
if (item.comparison_operator === 'AND') {
|
|
299
|
+
return isPassValidation.every(_i => _i);
|
|
300
|
+
} else {
|
|
301
|
+
return isPassValidation.some(_i => _i);
|
|
302
|
+
}
|
|
279
303
|
} else {
|
|
280
304
|
return true;
|
|
281
305
|
}
|
|
@@ -256,7 +256,7 @@ class HydradxHandler {
|
|
|
256
256
|
|
|
257
257
|
switch (defaultError) {
|
|
258
258
|
case _sdk.PoolError.InsufficientTradingAmount:
|
|
259
|
-
return new _SwapError.SwapError(_swap2.SwapErrorType.
|
|
259
|
+
return new _SwapError.SwapError(_swap2.SwapErrorType.NOT_MEET_MIN_SWAP);
|
|
260
260
|
case _sdk.PoolError.TradeNotAllowed:
|
|
261
261
|
return new _SwapError.SwapError(_swap2.SwapErrorType.ERROR_FETCHING_QUOTE);
|
|
262
262
|
case _sdk.PoolError.MaxInRatioExceeded:
|
|
@@ -57,6 +57,7 @@ var _option = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("option");
|
|
|
57
57
|
var _updateSessions = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("updateSessions");
|
|
58
58
|
var _onSessionProposal = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("onSessionProposal");
|
|
59
59
|
var _onSessionRequest = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("onSessionRequest");
|
|
60
|
+
var _onPingReply = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("onPingReply");
|
|
60
61
|
var _createListener = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("createListener");
|
|
61
62
|
var _removeListener = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("removeListener");
|
|
62
63
|
var _checkClient = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("checkClient");
|
|
@@ -72,6 +73,9 @@ class WalletConnectService {
|
|
|
72
73
|
Object.defineProperty(this, _createListener, {
|
|
73
74
|
value: _createListener2
|
|
74
75
|
});
|
|
76
|
+
Object.defineProperty(this, _onPingReply, {
|
|
77
|
+
value: _onPingReply2
|
|
78
|
+
});
|
|
75
79
|
Object.defineProperty(this, _onSessionRequest, {
|
|
76
80
|
value: _onSessionRequest2
|
|
77
81
|
});
|
|
@@ -318,11 +322,31 @@ function _onSessionRequest2(requestEvent) {
|
|
|
318
322
|
}).catch(console.error);
|
|
319
323
|
}
|
|
320
324
|
}
|
|
325
|
+
async function _onPingReply2(_ref4) {
|
|
326
|
+
let {
|
|
327
|
+
topic
|
|
328
|
+
} = _ref4;
|
|
329
|
+
// Doc: https://specs.walletconnect.com/2.0/specs/clients/sign/session-events#session_ping
|
|
330
|
+
|
|
331
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _checkClient)[_checkClient]();
|
|
332
|
+
try {
|
|
333
|
+
var _requestSession$names, _requestSession$names2;
|
|
334
|
+
const requestSession = this.getSession(topic);
|
|
335
|
+
const sessionAccounts = (((_requestSession$names = requestSession.namespaces.eip155) === null || _requestSession$names === void 0 ? void 0 : _requestSession$names.accounts) || []).concat(((_requestSession$names2 = requestSession.namespaces.polkadot) === null || _requestSession$names2 === void 0 ? void 0 : _requestSession$names2.accounts) || []);
|
|
336
|
+
if (sessionAccounts.length > 0 && (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) {
|
|
337
|
+
await (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client].ping({
|
|
338
|
+
topic
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
} catch (e) {
|
|
342
|
+
console.error(e);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
321
345
|
function _createListener2() {
|
|
322
346
|
var _classPrivateFieldLoo14, _classPrivateFieldLoo15, _classPrivateFieldLoo16, _classPrivateFieldLoo17, _classPrivateFieldLoo18, _classPrivateFieldLoo19;
|
|
323
347
|
(_classPrivateFieldLoo14 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo14 === void 0 ? void 0 : _classPrivateFieldLoo14.on('session_proposal', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionProposal)[_onSessionProposal].bind(this));
|
|
324
348
|
(_classPrivateFieldLoo15 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo15 === void 0 ? void 0 : _classPrivateFieldLoo15.on('session_request', (0, _classPrivateFieldLooseBase2.default)(this, _onSessionRequest)[_onSessionRequest].bind(this));
|
|
325
|
-
(_classPrivateFieldLoo16 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_ping',
|
|
349
|
+
(_classPrivateFieldLoo16 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo16 === void 0 ? void 0 : _classPrivateFieldLoo16.on('session_ping', (0, _classPrivateFieldLooseBase2.default)(this, _onPingReply)[_onPingReply].bind(this));
|
|
326
350
|
(_classPrivateFieldLoo17 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo17 === void 0 ? void 0 : _classPrivateFieldLoo17.on('session_event', data => console.log('event', data));
|
|
327
351
|
(_classPrivateFieldLoo18 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo18 === void 0 ? void 0 : _classPrivateFieldLoo18.on('session_update', data => console.log('update', data));
|
|
328
352
|
(_classPrivateFieldLoo19 = (0, _classPrivateFieldLooseBase2.default)(this, _client)[_client]) === null || _classPrivateFieldLoo19 === void 0 ? void 0 : _classPrivateFieldLoo19.on('session_delete', (0, _classPrivateFieldLooseBase2.default)(this, _updateSessions)[_updateSessions].bind(this));
|
package/constants/index.d.ts
CHANGED
|
@@ -29,5 +29,6 @@ export declare const GAS_PRICE_RATIO: number;
|
|
|
29
29
|
export declare const NETWORK_MULTI_GAS_FEE: string[];
|
|
30
30
|
export declare const ORDINAL_COLLECTION = "__Ordinal__";
|
|
31
31
|
export declare const ORDINAL_METHODS: string[];
|
|
32
|
+
export declare const PERMISSIONS_TO_REVOKE: string[];
|
|
32
33
|
export * from './staking';
|
|
33
34
|
export * from './storage';
|
package/constants/index.js
CHANGED
|
@@ -32,5 +32,6 @@ export const GAS_PRICE_RATIO = 1 + 2 / 100;
|
|
|
32
32
|
export const NETWORK_MULTI_GAS_FEE = ['*'];
|
|
33
33
|
export const ORDINAL_COLLECTION = '__Ordinal__';
|
|
34
34
|
export const ORDINAL_METHODS = ['drc-20', 'pol-20'];
|
|
35
|
+
export const PERMISSIONS_TO_REVOKE = ['eth_accounts'];
|
|
35
36
|
export * from "./staking.js";
|
|
36
37
|
export * from "./storage.js";
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ConfirmationType } from '@subwallet/extension-base/background/KoniTypes';
|
|
1
|
+
import { ConfirmationType, ErrorValidation } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
3
|
import { AuthUrlInfo } from '@subwallet/extension-base/services/request-service/types';
|
|
4
4
|
import { KeyringPair } from '@subwallet/keyring/types';
|
|
5
|
+
import Joi from 'joi';
|
|
5
6
|
export declare type ValidateStepFunction = (koni: KoniState, url: string, payload: PayloadValidated, topic?: string) => Promise<PayloadValidated>;
|
|
6
7
|
export interface PayloadValidated {
|
|
7
8
|
networkKey: string;
|
|
@@ -14,6 +15,25 @@ export interface PayloadValidated {
|
|
|
14
15
|
confirmationType?: ConfirmationType;
|
|
15
16
|
errors: Error[];
|
|
16
17
|
}
|
|
18
|
+
export declare type SignTypedDataMessageV3V4 = {
|
|
19
|
+
types: Record<string, unknown>;
|
|
20
|
+
domain: Record<string, unknown>;
|
|
21
|
+
primaryType: string;
|
|
22
|
+
message: unknown;
|
|
23
|
+
};
|
|
24
|
+
export declare type DataMessageParam = Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
|
|
25
|
+
export interface TypedMessageParams {
|
|
26
|
+
from: string;
|
|
27
|
+
data: DataMessageParam;
|
|
28
|
+
}
|
|
29
|
+
export interface PersonalMessageParams {
|
|
30
|
+
data: string;
|
|
31
|
+
from: string;
|
|
32
|
+
}
|
|
33
|
+
export declare const joiValidate: Joi.ObjectSchema<any>;
|
|
34
|
+
export declare function validateSignMessageData(messageData: PersonalMessageParams): string;
|
|
35
|
+
export declare function validateTypedSignMessageDataV1(messageData: TypedMessageParams): Record<string, unknown>[];
|
|
36
|
+
export declare function validateTypedSignMessageDataV3V4(messageData: TypedMessageParams): SignTypedDataMessageV3V4;
|
|
17
37
|
export declare function generateValidationProcess(koni: KoniState, url: string, payloadValidate: PayloadValidated, validationMiddlewareSteps: ValidateStepFunction[], topic?: string): Promise<PayloadValidated>;
|
|
18
38
|
export declare function validationAuthMiddleware(koni: KoniState, url: string, payload: PayloadValidated): Promise<PayloadValidated>;
|
|
19
39
|
export declare function validationConnectMiddleware(koni: KoniState, url: string, payload: PayloadValidated): Promise<PayloadValidated>;
|
|
@@ -21,3 +41,4 @@ export declare function validationEvmDataTransactionMiddleware(koni: KoniState,
|
|
|
21
41
|
export declare function validationEvmSignMessageMiddleware(koni: KoniState, url: string, payload_: PayloadValidated): Promise<PayloadValidated>;
|
|
22
42
|
export declare function validationAuthWCMiddleware(koni: KoniState, url: string, payload: PayloadValidated, topic?: string): Promise<PayloadValidated>;
|
|
23
43
|
export declare function convertErrorMessage(message_: string, name?: string): string[];
|
|
44
|
+
export declare function convertErrorFormat(errors: Error[]): ErrorValidation[];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { typedSignatureHash } from '@metamask/eth-sig-util';
|
|
4
5
|
import { EvmProviderError } from '@subwallet/extension-base/background/errors/EvmProviderError';
|
|
5
6
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
6
7
|
import { BasicTxErrorType, EvmProviderErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
@@ -12,8 +13,105 @@ import { getSdkError } from '@walletconnect/utils';
|
|
|
12
13
|
import BigN from 'bignumber.js';
|
|
13
14
|
import BN from 'bn.js';
|
|
14
15
|
import { t } from 'i18next';
|
|
16
|
+
import Joi from 'joi';
|
|
15
17
|
import { isString } from '@polkadot/util';
|
|
16
18
|
import { isEthereumAddress } from '@polkadot/util-crypto';
|
|
19
|
+
export const joiValidate = Joi.object({
|
|
20
|
+
types: Joi.object().pattern(Joi.string(),
|
|
21
|
+
// Key của object types
|
|
22
|
+
Joi.array().items(Joi.object({
|
|
23
|
+
name: Joi.string().required(),
|
|
24
|
+
type: Joi.string().required()
|
|
25
|
+
}))).required(),
|
|
26
|
+
primaryType: Joi.string().required(),
|
|
27
|
+
domain: Joi.object().required(),
|
|
28
|
+
message: Joi.object().required()
|
|
29
|
+
});
|
|
30
|
+
function validateAddress(address, propertyName) {
|
|
31
|
+
if (!address || typeof address !== 'string' || !isEthereumAddress(address)) {
|
|
32
|
+
throw new Error(`Invalid "${propertyName}" address: ${address} must be a valid string.`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export function validateSignMessageData(messageData) {
|
|
36
|
+
const {
|
|
37
|
+
data,
|
|
38
|
+
from
|
|
39
|
+
} = messageData;
|
|
40
|
+
validateAddress(from, 'from');
|
|
41
|
+
if (!data || typeof data !== 'string') {
|
|
42
|
+
throw new Error(`Invalid message "data": ${data} must be a valid string.`);
|
|
43
|
+
}
|
|
44
|
+
return data;
|
|
45
|
+
}
|
|
46
|
+
export function validateTypedSignMessageDataV1(messageData) {
|
|
47
|
+
validateAddress(messageData.from, 'from');
|
|
48
|
+
if (!messageData.data || !Array.isArray(messageData.data)) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
52
|
+
`Invalid message "data": ${messageData.data} must be a valid array.`);
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
// typedSignatureHash will throw if the data is invalid.
|
|
56
|
+
// TODO: Replace `any` with type
|
|
57
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
+
typedSignatureHash(messageData.data);
|
|
59
|
+
return messageData.data;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw new Error('Invalid message "data": Expected EIP712 typed data.');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function validateTypedSignMessageDataV3V4(messageData) {
|
|
65
|
+
validateAddress(messageData.from, 'from');
|
|
66
|
+
if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== 'object' && typeof messageData.data !== 'string') {
|
|
67
|
+
throw new Error('Invalid message "data": Must be a valid string or object.');
|
|
68
|
+
}
|
|
69
|
+
let data;
|
|
70
|
+
if (typeof messageData.data === 'object') {
|
|
71
|
+
data = messageData.data;
|
|
72
|
+
} else {
|
|
73
|
+
try {
|
|
74
|
+
data = JSON.parse(messageData.data);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
throw new Error('Invalid message "data" must be passed as a valid JSON string.');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const validation = joiValidate.validate(data);
|
|
80
|
+
if (validation.error) {
|
|
81
|
+
throw new Error('Invalid message "data" must conform to EIP-712 schema. See https://git.io/fNtcx.');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// if (!currentChainId) {
|
|
85
|
+
// throw new Error('Current chainId cannot be null or undefined.');
|
|
86
|
+
// }
|
|
87
|
+
|
|
88
|
+
// let { chainId } = data.domain;
|
|
89
|
+
//
|
|
90
|
+
// if (chainId) {
|
|
91
|
+
// if (typeof chainId === 'string') {
|
|
92
|
+
// chainId = parseInt(chainId, chainId.startsWith('0x') ? 16 : 10);
|
|
93
|
+
// }
|
|
94
|
+
//
|
|
95
|
+
// const activeChainId = parseInt(currentChainId, 16);
|
|
96
|
+
//
|
|
97
|
+
// if (Number.isNaN(activeChainId)) {
|
|
98
|
+
// throw new Error(
|
|
99
|
+
// // TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
100
|
+
// // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
101
|
+
// `Cannot sign messages for chainId "${chainId}", because MetaMask is switching networks.`
|
|
102
|
+
// );
|
|
103
|
+
// }
|
|
104
|
+
//
|
|
105
|
+
// if (chainId !== activeChainId) {
|
|
106
|
+
// throw new Error(
|
|
107
|
+
// // TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
108
|
+
// // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
109
|
+
// `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`
|
|
110
|
+
// );
|
|
111
|
+
// }
|
|
112
|
+
// }
|
|
113
|
+
return data;
|
|
114
|
+
}
|
|
17
115
|
export async function generateValidationProcess(koni, url, payloadValidate, validationMiddlewareSteps, topic) {
|
|
18
116
|
let resultValidated = payloadValidate;
|
|
19
117
|
for (const step of validationMiddlewareSteps) {
|
|
@@ -315,7 +413,7 @@ export async function validationEvmSignMessageMiddleware(koni, url, payload_) {
|
|
|
315
413
|
const [message, name] = convertErrorMessage(message_);
|
|
316
414
|
const error = new EvmProviderError(EvmProviderErrorType.INVALID_PARAMS, message, undefined, name);
|
|
317
415
|
console.error(error);
|
|
318
|
-
errors.push(
|
|
416
|
+
errors.push(error);
|
|
319
417
|
};
|
|
320
418
|
if (address === '' || !payload) {
|
|
321
419
|
handleError('Not found address or payload to sign');
|
|
@@ -329,26 +427,47 @@ export async function validationEvmSignMessageMiddleware(koni, url, payload_) {
|
|
|
329
427
|
if (['eth_sign', 'personal_sign', 'eth_signTypedData', 'eth_signTypedData_v1', 'eth_signTypedData_v3', 'eth_signTypedData_v4'].indexOf(method) < 0) {
|
|
330
428
|
handleError('Unsupported action');
|
|
331
429
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
switch (method) {
|
|
337
|
-
case 'personal_sign':
|
|
338
|
-
canSign = true;
|
|
339
|
-
hashPayload = payload;
|
|
340
|
-
break;
|
|
341
|
-
case 'eth_sign':
|
|
342
|
-
case 'eth_signTypedData':
|
|
343
|
-
case 'eth_signTypedData_v1':
|
|
344
|
-
case 'eth_signTypedData_v3':
|
|
345
|
-
case 'eth_signTypedData_v4':
|
|
346
|
-
if (!account.isExternal) {
|
|
430
|
+
try {
|
|
431
|
+
switch (method) {
|
|
432
|
+
case 'personal_sign':
|
|
347
433
|
canSign = true;
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
434
|
+
payload = validateSignMessageData({
|
|
435
|
+
data: payload,
|
|
436
|
+
from: address
|
|
437
|
+
});
|
|
438
|
+
hashPayload = payload;
|
|
439
|
+
break;
|
|
440
|
+
case 'eth_sign':
|
|
441
|
+
if (!account.isExternal) {
|
|
442
|
+
canSign = true;
|
|
443
|
+
}
|
|
444
|
+
break;
|
|
445
|
+
case 'eth_signTypedData':
|
|
446
|
+
case 'eth_signTypedData_v1':
|
|
447
|
+
if (!account.isExternal) {
|
|
448
|
+
canSign = true;
|
|
449
|
+
}
|
|
450
|
+
payload = validateTypedSignMessageDataV1({
|
|
451
|
+
data: payload,
|
|
452
|
+
from: address
|
|
453
|
+
});
|
|
454
|
+
break;
|
|
455
|
+
case 'eth_signTypedData_v3':
|
|
456
|
+
case 'eth_signTypedData_v4':
|
|
457
|
+
if (!account.isExternal) {
|
|
458
|
+
canSign = true;
|
|
459
|
+
}
|
|
460
|
+
payload = validateTypedSignMessageDataV3V4({
|
|
461
|
+
data: payload,
|
|
462
|
+
from: address
|
|
463
|
+
});
|
|
464
|
+
break;
|
|
465
|
+
default:
|
|
466
|
+
throw new Error('Unsupported action');
|
|
467
|
+
}
|
|
468
|
+
} catch (e) {
|
|
469
|
+
console.error(e);
|
|
470
|
+
handleError(e.message);
|
|
352
471
|
}
|
|
353
472
|
} else {
|
|
354
473
|
handleError('Unsupported method');
|
|
@@ -429,7 +548,7 @@ export function convertErrorMessage(message_, name) {
|
|
|
429
548
|
return [t('Re-enable the network or change RPC on the extension and try again'), t('Unstable network connection')];
|
|
430
549
|
}
|
|
431
550
|
if (message.includes('network is currently not supported')) {
|
|
432
|
-
return [t('This network is not yet supported on SubWallet.
|
|
551
|
+
return [t('This network is not yet supported on SubWallet. (Import the network)[https://docs.subwallet.app/main/extension-user-guide/customize-your-networks#import-networks] on SubWallet and try again'), t('Network not supported')];
|
|
433
552
|
}
|
|
434
553
|
|
|
435
554
|
// Authentication
|
|
@@ -466,10 +585,22 @@ export function convertErrorMessage(message_, name) {
|
|
|
466
585
|
|
|
467
586
|
// Sign Message
|
|
468
587
|
if (message.includes('not found address or payload to sign')) {
|
|
469
|
-
return [t('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), t('Unable to sign
|
|
588
|
+
return [t('An error occurred when signing this request. Try again or contact support at agent@subwallet.app'), t('Unable to sign')];
|
|
470
589
|
}
|
|
471
590
|
if (message.includes('unsupported method') || message.includes('unsupported action')) {
|
|
472
591
|
return [t('This sign method is not supported by SubWallet. Try again or contact support at agent@subwallet.app'), t('Method not supported')];
|
|
473
592
|
}
|
|
474
|
-
|
|
593
|
+
if (message.includes('eip712 typed data') || message.includes('invalid message')) {
|
|
594
|
+
return [t('An error occurred when attempting to sign this request. Contact support at email: agent@subwallet.app'), t('Unable to sign')];
|
|
595
|
+
}
|
|
596
|
+
return [message, name || 'Error'];
|
|
597
|
+
}
|
|
598
|
+
export function convertErrorFormat(errors) {
|
|
599
|
+
if (errors.length > 0) {
|
|
600
|
+
return [{
|
|
601
|
+
name: errors[0].name,
|
|
602
|
+
message: errors[0].message
|
|
603
|
+
}];
|
|
604
|
+
}
|
|
605
|
+
return [];
|
|
475
606
|
}
|
|
@@ -47,8 +47,9 @@ export declare function _getXcmMultiLocation(originChainInfo: _ChainInfo, destCh
|
|
|
47
47
|
interior: unknown;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
51
|
-
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): string;
|
|
50
|
+
export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
51
|
+
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): string;
|
|
52
52
|
export declare function _isXcmWithinSameConsensus(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
53
53
|
export declare function _isSnowBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
54
|
+
export declare function _isMythosFromHydrationToMythos(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
54
55
|
export declare function _adaptX1Interior(assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -46,8 +46,8 @@ export function _getXcmMultiLocation(originChainInfo, destChainInfo, version, re
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
export function _isXcmTransferUnstable(originChainInfo, destChainInfo) {
|
|
50
|
-
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo);
|
|
49
|
+
export function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
|
|
50
|
+
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug);
|
|
51
51
|
}
|
|
52
52
|
function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
53
53
|
switch (originChainInfo.slug) {
|
|
@@ -62,16 +62,21 @@ function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
|
62
62
|
function getSnowBridgeUnstableWarning(originChainInfo) {
|
|
63
63
|
switch (originChainInfo.slug) {
|
|
64
64
|
case COMMON_CHAIN_SLUGS.POLKADOT_ASSET_HUB:
|
|
65
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 70
|
|
65
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $70 and takes up to 1 hour to complete. Continue at your own risk';
|
|
66
66
|
case COMMON_CHAIN_SLUGS.ETHEREUM:
|
|
67
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 5
|
|
67
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $5 and takes up to 1 hour to complete. Continue at your own risk';
|
|
68
68
|
default:
|
|
69
69
|
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a high fee and takes up to 1 hour to complete. Continue at your own risk';
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
function getMythosFromHydrationToMythosWarning() {
|
|
73
|
+
return 'Cross-chain transfer of this token requires a high transaction fee. Do you want to continue?';
|
|
74
|
+
}
|
|
75
|
+
export function _getXcmUnstableWarning(originChainInfo, destChainInfo, assetSlug) {
|
|
73
76
|
if (_isSnowBridgeXcm(originChainInfo, destChainInfo)) {
|
|
74
77
|
return getSnowBridgeUnstableWarning(originChainInfo);
|
|
78
|
+
} else if (_isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug)) {
|
|
79
|
+
return getMythosFromHydrationToMythosWarning();
|
|
75
80
|
} else {
|
|
76
81
|
return getAssetHubBridgeUnstableWarning(originChainInfo);
|
|
77
82
|
}
|
|
@@ -82,6 +87,9 @@ export function _isXcmWithinSameConsensus(originChainInfo, destChainInfo) {
|
|
|
82
87
|
export function _isSnowBridgeXcm(originChainInfo, destChainInfo) {
|
|
83
88
|
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) && (_isPureEvmChain(originChainInfo) || _isPureEvmChain(destChainInfo));
|
|
84
89
|
}
|
|
90
|
+
export function _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) {
|
|
91
|
+
return originChainInfo.slug === 'hydradx_main' && destChainInfo.slug === 'mythos' && assetSlug === 'hydradx_main-LOCAL-MYTH';
|
|
92
|
+
}
|
|
85
93
|
|
|
86
94
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
87
95
|
|
|
@@ -195,7 +203,8 @@ function _getAssetIdentifier(tokenInfo, version) {
|
|
|
195
203
|
if (!_assetIdentifier) {
|
|
196
204
|
throw new Error('Asset must have multilocation');
|
|
197
205
|
}
|
|
198
|
-
const assetIdentifier =
|
|
206
|
+
const assetIdentifier = ['statemint-LOCAL-KSM', 'statemine-LOCAL-DOT'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
207
|
+
? _assetIdentifier : _adaptX1Interior(structuredClone(_assetIdentifier), version);
|
|
199
208
|
return version >= 4 // from V4, Concrete is removed
|
|
200
209
|
? assetIdentifier : {
|
|
201
210
|
Concrete: assetIdentifier
|
|
@@ -103,6 +103,7 @@ export function calculateTernoaValidatorReturn(rewardPerValidator, validatorStak
|
|
|
103
103
|
export function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
|
|
104
104
|
const bnAdjusted = avgStake.mul(BN_HUNDRED).div(totalValidatorStake);
|
|
105
105
|
const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
|
|
106
|
+
// todo: should calculated in bignumber instead number?
|
|
106
107
|
const stakedReturn = (adjusted > Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : adjusted) / 100;
|
|
107
108
|
return stakedReturn * (100 - commission) / 100; // Deduct commission
|
|
108
109
|
}
|
|
@@ -1711,11 +1711,11 @@ export default class KoniExtension {
|
|
|
1711
1711
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1712
1712
|
}
|
|
1713
1713
|
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
1714
|
-
const
|
|
1714
|
+
const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]);
|
|
1715
1715
|
let additionalValidator;
|
|
1716
1716
|
let eventsHandler;
|
|
1717
1717
|
if (fromKeyPair && destinationTokenInfo) {
|
|
1718
|
-
if (
|
|
1718
|
+
if (isSnowBridgeEvmTransfer) {
|
|
1719
1719
|
const evmApi = this.#koniState.getEvmApi(originNetworkKey);
|
|
1720
1720
|
extrinsic = await createSnowBridgeExtrinsic({
|
|
1721
1721
|
destinationTokenInfo,
|
|
@@ -1785,7 +1785,7 @@ export default class KoniExtension {
|
|
|
1785
1785
|
transaction: extrinsic,
|
|
1786
1786
|
data: inputData,
|
|
1787
1787
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
1788
|
-
chainType: !
|
|
1788
|
+
chainType: !isSnowBridgeEvmTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1789
1789
|
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
|
|
1790
1790
|
ignoreWarnings: inputData.transferAll,
|
|
1791
1791
|
isTransferAll: inputData.transferAll,
|
|
@@ -145,7 +145,6 @@ export default class KoniState {
|
|
|
145
145
|
setCurrentAccount(data: CurrentAccountInfo, callback?: () => void, preventOneAccount?: boolean): void;
|
|
146
146
|
setAccountTie(address: string, genesisHash: string | null): boolean;
|
|
147
147
|
switchEvmNetworkByUrl(shortenUrl: string, networkKey: string): Promise<void>;
|
|
148
|
-
switchNetworkAccount(id: string, url: string, networkKey: string, changeAddress?: string): Promise<boolean>;
|
|
149
148
|
addNetworkConfirm(id: string, url: string, networkData: _NetworkUpsertParams): Promise<null>;
|
|
150
149
|
addTokenConfirm(id: string, url: string, tokenInfo: AddTokenRequestExternal): Promise<true>;
|
|
151
150
|
get metaSubject(): BehaviorSubject<import("@subwallet/extension-base/background/types").MetadataRequest[]>;
|