@subwallet/extension-base 1.0.11-2 → 1.0.13-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 +52 -0
- package/background/KoniTypes.js +10 -18
- package/background/handlers/State.d.ts +0 -1
- package/background/handlers/State.js +4 -8
- package/cjs/background/KoniTypes.js +12 -10
- package/cjs/background/handlers/State.js +4 -8
- package/cjs/koni/api/nft/config.js +11 -6
- package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
- package/cjs/koni/api/xcm/xTokens.js +2 -2
- package/cjs/koni/background/handlers/Extension.js +150 -1
- package/cjs/koni/background/handlers/State.js +14 -3
- package/cjs/koni/background/handlers/Tabs.js +61 -9
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Metadata.js +3 -0
- package/cjs/services/chain-service/utils.js +28 -1
- package/cjs/services/migration-service/scripts/MigrateEthProvider.js +32 -0
- package/cjs/services/migration-service/scripts/index.js +12 -10
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -9
- package/cjs/services/request-service/handler/SubstrateRequestHandler.js +2 -2
- package/cjs/services/request-service/handler/WalletConnectRequestHandler.js +71 -0
- package/cjs/services/request-service/index.js +24 -6
- package/cjs/services/transaction-service/helpers/index.js +3 -2
- package/cjs/services/transaction-service/index.js +2 -1
- package/cjs/services/wallet-connect-service/constants.js +38 -0
- package/cjs/services/wallet-connect-service/handler/Eip155RequestHandler.js +113 -0
- package/cjs/services/wallet-connect-service/handler/PolkadotRequestHandler.js +123 -0
- package/cjs/services/wallet-connect-service/helpers.js +81 -0
- package/cjs/services/wallet-connect-service/index.js +273 -0
- package/cjs/services/wallet-connect-service/types.js +27 -0
- package/cjs/utils/array.js +17 -0
- package/cjs/utils/environment.js +66 -0
- package/cjs/utils/index.js +66 -1
- package/koni/api/nft/config.js +11 -6
- package/koni/api/xcm/polkadotXcm.js +1 -1
- package/koni/api/xcm/xTokens.js +2 -2
- package/koni/background/handlers/Extension.d.ts +6 -0
- package/koni/background/handlers/Extension.js +144 -2
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +14 -3
- package/koni/background/handlers/Tabs.d.ts +2 -0
- package/koni/background/handlers/Tabs.js +58 -7
- package/package.json +72 -18
- package/packageInfo.js +1 -1
- package/page/Metadata.d.ts +2 -0
- package/page/Metadata.js +3 -0
- package/services/chain-service/utils.d.ts +2 -0
- package/services/chain-service/utils.js +25 -1
- package/services/migration-service/scripts/MigrateEthProvider.d.ts +4 -0
- package/services/migration-service/scripts/MigrateEthProvider.js +24 -0
- package/services/migration-service/scripts/index.js +12 -10
- package/services/request-service/handler/AuthRequestHandler.d.ts +0 -1
- package/services/request-service/handler/AuthRequestHandler.js +5 -10
- package/services/request-service/handler/SubstrateRequestHandler.d.ts +1 -1
- package/services/request-service/handler/SubstrateRequestHandler.js +2 -2
- package/services/request-service/handler/WalletConnectRequestHandler.d.ts +15 -0
- package/services/request-service/handler/WalletConnectRequestHandler.js +62 -0
- package/services/request-service/index.d.ts +7 -2
- package/services/request-service/index.js +24 -6
- package/services/transaction-service/helpers/index.d.ts +1 -1
- package/services/transaction-service/helpers/index.js +2 -2
- package/services/transaction-service/index.js +2 -1
- package/services/transaction-service/types.d.ts +2 -1
- package/services/wallet-connect-service/constants.d.ts +11 -0
- package/services/wallet-connect-service/constants.js +23 -0
- package/services/wallet-connect-service/handler/Eip155RequestHandler.d.ts +8 -0
- package/services/wallet-connect-service/handler/Eip155RequestHandler.js +106 -0
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.d.ts +8 -0
- package/services/wallet-connect-service/handler/PolkadotRequestHandler.js +114 -0
- package/services/wallet-connect-service/helpers.d.ts +12 -0
- package/services/wallet-connect-service/helpers.js +67 -0
- package/services/wallet-connect-service/index.d.ts +20 -0
- package/services/wallet-connect-service/index.js +265 -0
- package/services/wallet-connect-service/types.d.ts +46 -0
- package/services/wallet-connect-service/types.js +20 -0
- package/utils/array.d.ts +1 -0
- package/utils/array.js +10 -0
- package/utils/environment.d.ts +2 -0
- package/utils/environment.js +59 -0
- package/utils/index.d.ts +3 -0
- package/utils/index.js +9 -2
|
@@ -6,10 +6,12 @@ import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, Confirmati
|
|
|
6
6
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
7
7
|
import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
8
|
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
|
|
9
|
+
import { WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
|
|
9
10
|
import { InjectedAccount, MetadataDefBase } from '@subwallet/extension-inject/types';
|
|
10
11
|
import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
|
|
11
12
|
import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
|
|
12
13
|
import { KeyringAddress, KeyringPairs$Json } from '@subwallet/ui-keyring/types';
|
|
14
|
+
import { SessionTypes } from '@walletconnect/types/dist/types/sign-client/session';
|
|
13
15
|
import Web3 from 'web3';
|
|
14
16
|
import { RequestArguments, TransactionConfig } from 'web3-core';
|
|
15
17
|
import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers';
|
|
@@ -18,6 +20,21 @@ import { BN } from '@polkadot/util';
|
|
|
18
20
|
import { HexString } from '@polkadot/util/types';
|
|
19
21
|
import { KeypairType } from '@polkadot/util-crypto/types';
|
|
20
22
|
import { TransactionWarning } from './warnings/TransactionWarning';
|
|
23
|
+
export declare enum RuntimeEnvironment {
|
|
24
|
+
Web = "Web",
|
|
25
|
+
Node = "Node",
|
|
26
|
+
ExtensionChrome = "Extension (Chrome)",
|
|
27
|
+
ExtensionFirefox = "Extension (Firefox)",
|
|
28
|
+
WebWorker = "Web Worker",
|
|
29
|
+
ServiceWorker = "Service Worker",
|
|
30
|
+
Unknown = "Unknown"
|
|
31
|
+
}
|
|
32
|
+
export interface RuntimeEnvironmentInfo {
|
|
33
|
+
environment: RuntimeEnvironment;
|
|
34
|
+
version: string;
|
|
35
|
+
host?: string;
|
|
36
|
+
protocol?: string;
|
|
37
|
+
}
|
|
21
38
|
export interface ServiceInfo {
|
|
22
39
|
chainInfoMap: Record<string, _ChainInfo>;
|
|
23
40
|
chainStateMap: Record<string, _ChainState>;
|
|
@@ -1407,6 +1424,33 @@ export interface PassPhishing {
|
|
|
1407
1424
|
export interface RequestPassPhishingPage {
|
|
1408
1425
|
url: string;
|
|
1409
1426
|
}
|
|
1427
|
+
export interface RequestAddPspToken {
|
|
1428
|
+
genesisHash: string;
|
|
1429
|
+
tokenInfo: {
|
|
1430
|
+
type: string;
|
|
1431
|
+
address: string;
|
|
1432
|
+
symbol: string;
|
|
1433
|
+
name: string;
|
|
1434
|
+
decimals?: number;
|
|
1435
|
+
logo?: string;
|
|
1436
|
+
};
|
|
1437
|
+
}
|
|
1438
|
+
export interface RequestConnectWalletConnect {
|
|
1439
|
+
uri: string;
|
|
1440
|
+
}
|
|
1441
|
+
export interface RequestRejectConnectWalletSession {
|
|
1442
|
+
id: string;
|
|
1443
|
+
}
|
|
1444
|
+
export interface RequestApproveConnectWalletSession {
|
|
1445
|
+
id: string;
|
|
1446
|
+
accounts: string[];
|
|
1447
|
+
}
|
|
1448
|
+
export interface RequestReconnectConnectWalletSession {
|
|
1449
|
+
id: string;
|
|
1450
|
+
}
|
|
1451
|
+
export interface RequestDisconnectWalletConnectSession {
|
|
1452
|
+
topic: string;
|
|
1453
|
+
}
|
|
1410
1454
|
export interface KoniRequestSignatures {
|
|
1411
1455
|
'pri(staking.submitTuringCancelCompound)': [RequestTuringCancelStakeCompound, SWTransactionResponse];
|
|
1412
1456
|
'pri(staking.submitTuringCompound)': [RequestTuringStakeCompound, SWTransactionResponse];
|
|
@@ -1561,6 +1605,14 @@ export interface KoniRequestSignatures {
|
|
|
1561
1605
|
'mobile(subscription.start)': [SubscriptionServiceType[], void];
|
|
1562
1606
|
'mobile(subscription.stop)': [SubscriptionServiceType[], void];
|
|
1563
1607
|
'mobile(subscription.restart)': [SubscriptionServiceType[], void];
|
|
1608
|
+
'pub(token.add)': [RequestAddPspToken, boolean];
|
|
1609
|
+
'pri(walletConnect.connect)': [RequestConnectWalletConnect, boolean];
|
|
1610
|
+
'pri(walletConnect.requests.subscribe)': [null, WalletConnectSessionRequest[], WalletConnectSessionRequest[]];
|
|
1611
|
+
'pri(walletConnect.session.approve)': [RequestApproveConnectWalletSession, boolean];
|
|
1612
|
+
'pri(walletConnect.session.reject)': [RequestRejectConnectWalletSession, boolean];
|
|
1613
|
+
'pri(walletConnect.session.reconnect)': [RequestReconnectConnectWalletSession, boolean];
|
|
1614
|
+
'pri(walletConnect.session.subscribe)': [null, SessionTypes.Struct[], SessionTypes.Struct[]];
|
|
1615
|
+
'pri(walletConnect.session.disconnect)': [RequestDisconnectWalletConnectSession, boolean];
|
|
1564
1616
|
}
|
|
1565
1617
|
export interface ApplicationMetadataType {
|
|
1566
1618
|
version: string;
|
package/background/KoniTypes.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
// Copyright 2019-2022 @polkadot/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Manage single auth with single account
|
|
15
|
-
|
|
16
|
-
// Manage single site with multi account
|
|
17
|
-
|
|
18
|
-
// Manage site block
|
|
19
|
-
|
|
20
|
-
// Forget site auth
|
|
21
|
-
|
|
4
|
+
export let RuntimeEnvironment;
|
|
5
|
+
(function (RuntimeEnvironment) {
|
|
6
|
+
RuntimeEnvironment["Web"] = "Web";
|
|
7
|
+
RuntimeEnvironment["Node"] = "Node";
|
|
8
|
+
RuntimeEnvironment["ExtensionChrome"] = "Extension (Chrome)";
|
|
9
|
+
RuntimeEnvironment["ExtensionFirefox"] = "Extension (Firefox)";
|
|
10
|
+
RuntimeEnvironment["WebWorker"] = "Web Worker";
|
|
11
|
+
RuntimeEnvironment["ServiceWorker"] = "Service Worker";
|
|
12
|
+
RuntimeEnvironment["Unknown"] = "Unknown";
|
|
13
|
+
})(RuntimeEnvironment || (RuntimeEnvironment = {}));
|
|
22
14
|
/// Staking subscribe
|
|
23
15
|
|
|
24
16
|
export let StakingType;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { DEFAULT_SETTING } from '@subwallet/extension-base/services/setting-service/constants';
|
|
5
5
|
import SettingsStore from '@subwallet/extension-base/stores/Settings';
|
|
6
|
+
import { stripUrl } from '@subwallet/extension-base/utils';
|
|
6
7
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
7
8
|
import { addMetadata, knownMetadata } from '@subwallet/extension-chains';
|
|
8
9
|
import { BehaviorSubject } from 'rxjs';
|
|
@@ -206,7 +207,7 @@ export default class State {
|
|
|
206
207
|
url
|
|
207
208
|
} = this.#authRequests[id];
|
|
208
209
|
const isAllowedMap = {};
|
|
209
|
-
this.#authUrls[
|
|
210
|
+
this.#authUrls[stripUrl(url)] = {
|
|
210
211
|
count: 0,
|
|
211
212
|
id: idStr,
|
|
212
213
|
isAllowed,
|
|
@@ -264,11 +265,6 @@ export default class State {
|
|
|
264
265
|
}
|
|
265
266
|
};
|
|
266
267
|
};
|
|
267
|
-
stripUrl(url) {
|
|
268
|
-
assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
269
|
-
const parts = url.split('/');
|
|
270
|
-
return parts[2];
|
|
271
|
-
}
|
|
272
268
|
updateIcon(shouldClose) {
|
|
273
269
|
const authCount = this.numAuthRequests;
|
|
274
270
|
const metaCount = this.numMetaRequests;
|
|
@@ -304,7 +300,7 @@ export default class State {
|
|
|
304
300
|
this.updateIcon(shouldClose);
|
|
305
301
|
}
|
|
306
302
|
async authorizeUrl(url, request) {
|
|
307
|
-
const idStr =
|
|
303
|
+
const idStr = stripUrl(url);
|
|
308
304
|
|
|
309
305
|
// Do not enqueue duplicate authorization requests.
|
|
310
306
|
const isDuplicate = Object.values(this.#authRequests).some(request => request.idStr === idStr);
|
|
@@ -328,7 +324,7 @@ export default class State {
|
|
|
328
324
|
});
|
|
329
325
|
}
|
|
330
326
|
ensureUrlAuthorized(url) {
|
|
331
|
-
const entry = this.#authUrls[
|
|
327
|
+
const entry = this.#authUrls[stripUrl(url)];
|
|
332
328
|
assert(entry, `The source ${url} has not been enabled yet`);
|
|
333
329
|
assert(entry.isAllowed, `The source ${url} is not allowed to interact with this extension`);
|
|
334
330
|
return true;
|
|
@@ -3,18 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.StakingStatus = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
|
|
6
|
+
exports.UnstakingStatus = exports.TransferTxErrorType = exports.TransactionDirection = exports.ThemeNames = exports.StakingType = exports.StakingTxErrorType = exports.StakingStatus = exports.RuntimeEnvironment = exports.RMRK_VER = exports.ProviderErrorType = exports.NotificationType = exports.NETWORK_STATUS = exports.NETWORK_ERROR = exports.ExtrinsicType = exports.ExtrinsicStatus = exports.ExternalRequestPromiseStatus = exports.EvmProviderErrorType = exports.CrowdloanParaState = exports.ContractType = exports.ChainType = exports.ChainEditStandard = exports.BasicTxWarningCode = exports.BasicTxErrorType = exports.BalanceErrorType = exports.AccountExternalErrorCode = exports.APIItemState = void 0;
|
|
7
7
|
// Copyright 2019-2022 @polkadot/extension-koni authors & contributors
|
|
8
8
|
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
let RuntimeEnvironment;
|
|
10
|
+
exports.RuntimeEnvironment = RuntimeEnvironment;
|
|
11
|
+
(function (RuntimeEnvironment) {
|
|
12
|
+
RuntimeEnvironment["Web"] = "Web";
|
|
13
|
+
RuntimeEnvironment["Node"] = "Node";
|
|
14
|
+
RuntimeEnvironment["ExtensionChrome"] = "Extension (Chrome)";
|
|
15
|
+
RuntimeEnvironment["ExtensionFirefox"] = "Extension (Firefox)";
|
|
16
|
+
RuntimeEnvironment["WebWorker"] = "Web Worker";
|
|
17
|
+
RuntimeEnvironment["ServiceWorker"] = "Service Worker";
|
|
18
|
+
RuntimeEnvironment["Unknown"] = "Unknown";
|
|
19
|
+
})(RuntimeEnvironment || (exports.RuntimeEnvironment = RuntimeEnvironment = {}));
|
|
18
20
|
/// Staking subscribe
|
|
19
21
|
let StakingType;
|
|
20
22
|
exports.StakingType = StakingType;
|
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = exports.NotificationOptions = void 0;
|
|
8
8
|
var _constants = require("@subwallet/extension-base/services/setting-service/constants");
|
|
9
9
|
var _Settings = _interopRequireDefault(require("@subwallet/extension-base/stores/Settings"));
|
|
10
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
10
11
|
var _getId = require("@subwallet/extension-base/utils/getId");
|
|
11
12
|
var _extensionChains = require("@subwallet/extension-chains");
|
|
12
13
|
var _rxjs = require("rxjs");
|
|
@@ -232,7 +233,7 @@ class State {
|
|
|
232
233
|
url
|
|
233
234
|
} = this.#authRequests[id];
|
|
234
235
|
const isAllowedMap = {};
|
|
235
|
-
this.#authUrls[
|
|
236
|
+
this.#authUrls[(0, _utils.stripUrl)(url)] = {
|
|
236
237
|
count: 0,
|
|
237
238
|
id: idStr,
|
|
238
239
|
isAllowed,
|
|
@@ -290,11 +291,6 @@ class State {
|
|
|
290
291
|
}
|
|
291
292
|
};
|
|
292
293
|
};
|
|
293
|
-
stripUrl(url) {
|
|
294
|
-
(0, _util.assert)(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
295
|
-
const parts = url.split('/');
|
|
296
|
-
return parts[2];
|
|
297
|
-
}
|
|
298
294
|
updateIcon(shouldClose) {
|
|
299
295
|
const authCount = this.numAuthRequests;
|
|
300
296
|
const metaCount = this.numMetaRequests;
|
|
@@ -330,7 +326,7 @@ class State {
|
|
|
330
326
|
this.updateIcon(shouldClose);
|
|
331
327
|
}
|
|
332
328
|
async authorizeUrl(url, request) {
|
|
333
|
-
const idStr =
|
|
329
|
+
const idStr = (0, _utils.stripUrl)(url);
|
|
334
330
|
|
|
335
331
|
// Do not enqueue duplicate authorization requests.
|
|
336
332
|
const isDuplicate = Object.values(this.#authRequests).some(request => request.idStr === idStr);
|
|
@@ -354,7 +350,7 @@ class State {
|
|
|
354
350
|
});
|
|
355
351
|
}
|
|
356
352
|
ensureUrlAuthorized(url) {
|
|
357
|
-
const entry = this.#authUrls[
|
|
353
|
+
const entry = this.#authUrls[(0, _utils.stripUrl)(url)];
|
|
358
354
|
(0, _util.assert)(entry, `The source ${url} has not been enabled yet`);
|
|
359
355
|
(0, _util.assert)(entry.isAllowed, `The source ${url} is not allowed to interact with this extension`);
|
|
360
356
|
return true;
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.UNIQUE_SCAN_ENDPOINT = exports.UNIQUE_IPFS_GATEWAY = exports.TRANSFER_CHAIN_ID = exports.SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = exports.SUPPORTED_TRANSFER_EVM_CHAIN_NAME = exports.SUPPORTED_TRANSFER_EVM_CHAIN = exports.SUPPORTED_NFT_NETWORKS = exports.SINGULAR_V2_ENDPOINT = exports.SINGULAR_V2_COLLECTION_ENDPOINT = exports.SINGULAR_V1_ENDPOINT = exports.SINGULAR_V1_COLLECTION_ENDPOINT = exports.RMRK_PINATA_SERVER = exports.QUARTZ_SCAN_ENDPOINT = exports.PINATA_IPFS_GATEWAY = exports.NFT_STORAGE_GATEWAY = exports.KANARIA_EXTERNAL_SERVER = exports.KANARIA_ENDPOINT = exports.IPFS_TELOS_MIAMI = exports.IPFS_IO_GATEWAY = exports.IPFS_GATEWAY_CLOUD = exports.IPFS_FLEEK = exports.GATEWAY_IPFS_IO = exports.DWEB_LINK = exports.CLOUDFLARE_PINATA_SERVER = exports.CF_IPFS_GATEWAY = exports.BIT_COUNTRY_THUMBNAIL_RESOLVER = exports.BIT_COUNTRY_SERVER = void 0;
|
|
7
7
|
exports.getRandomIpfsGateway = getRandomIpfsGateway;
|
|
8
|
+
var _utils = require("@subwallet/extension-base/utils");
|
|
8
9
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
9
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
10
11
|
|
|
@@ -102,9 +103,6 @@ exports.SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = SUPPORTED_TRANSFER_SUBSTRATE_C
|
|
|
102
103
|
const RANDOM_IPFS_GATEWAY_SETTING = [{
|
|
103
104
|
provider: IPFS_IO_GATEWAY,
|
|
104
105
|
weight: 0 // Not stable
|
|
105
|
-
}, {
|
|
106
|
-
provider: NFT_STORAGE_GATEWAY,
|
|
107
|
-
weight: 50
|
|
108
106
|
}, {
|
|
109
107
|
provider: CF_IPFS_GATEWAY,
|
|
110
108
|
weight: 4
|
|
@@ -123,13 +121,20 @@ const RANDOM_IPFS_GATEWAY_SETTING = [{
|
|
|
123
121
|
}, {
|
|
124
122
|
provider: IPFS_GATEWAY_CLOUD,
|
|
125
123
|
weight: 0 // Deceptive site warning
|
|
126
|
-
}, {
|
|
127
|
-
provider: IPFS_FLEEK,
|
|
128
|
-
weight: 4
|
|
129
124
|
}, {
|
|
130
125
|
provider: IPFS_TELOS_MIAMI,
|
|
131
126
|
weight: 0
|
|
132
127
|
}];
|
|
128
|
+
if (!_utils.RuntimeInfo.protocol || _utils.RuntimeInfo.protocol && !_utils.RuntimeInfo.protocol.startsWith('http')) {
|
|
129
|
+
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
130
|
+
provider: NFT_STORAGE_GATEWAY,
|
|
131
|
+
weight: 50
|
|
132
|
+
});
|
|
133
|
+
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
134
|
+
provider: IPFS_FLEEK,
|
|
135
|
+
weight: 4
|
|
136
|
+
});
|
|
137
|
+
}
|
|
133
138
|
const RANDOM_IPFS_GATEWAY_TOTAL_WEIGHT = RANDOM_IPFS_GATEWAY_SETTING.reduce((value, item) => value + item.weight, 0);
|
|
134
139
|
function getRandomIpfsGateway() {
|
|
135
140
|
const weighedItems = [];
|
|
@@ -11,7 +11,7 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
|
|
|
11
11
|
|
|
12
12
|
function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
13
13
|
const weightParam = (0, _utils.getDestWeight)();
|
|
14
|
-
const version = ['statemint', 'statemine', 'shiden'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
14
|
+
const version = ['statemint', 'statemine', 'shiden', 'astar'].includes(originChainInfo.slug) ? 'V3' : 'V1';
|
|
15
15
|
const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress, version);
|
|
16
16
|
const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo, version);
|
|
17
17
|
let assetLocation = (0, _utils.getTokenLocation)(tokenInfo, value, version);
|
|
@@ -24,7 +24,7 @@ function getCurrencyId(tokenInfo) {
|
|
|
24
24
|
return (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
|
|
25
25
|
}
|
|
26
26
|
function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
27
|
-
const weightParam = ['pioneer'
|
|
28
|
-
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
27
|
+
const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
|
|
28
|
+
const destVersion = ['moonbeam', 'moonriver', 'bifrost_dot', 'interlay', 'hydradx_main'].includes(originChainInfo.slug) ? 'V3' : undefined;
|
|
29
29
|
return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
|
|
30
30
|
}
|
|
@@ -27,6 +27,8 @@ var _xcm = require("@subwallet/extension-base/koni/api/xcm");
|
|
|
27
27
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
28
28
|
var _constants2 = require("@subwallet/extension-base/services/request-service/constants");
|
|
29
29
|
var _constants3 = require("@subwallet/extension-base/services/setting-service/constants");
|
|
30
|
+
var _constants4 = require("@subwallet/extension-base/services/wallet-connect-service/constants");
|
|
31
|
+
var _helpers2 = require("@subwallet/extension-base/services/wallet-connect-service/helpers");
|
|
30
32
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
31
33
|
var _address2 = require("@subwallet/extension-base/utils/address");
|
|
32
34
|
var _eth = require("@subwallet/extension-base/utils/eth");
|
|
@@ -34,6 +36,7 @@ var _parseTransaction2 = require("@subwallet/extension-base/utils/eth/parseTrans
|
|
|
34
36
|
var _number = require("@subwallet/extension-base/utils/number");
|
|
35
37
|
var _keyring = require("@subwallet/keyring");
|
|
36
38
|
var _uiKeyring = require("@subwallet/ui-keyring");
|
|
39
|
+
var _utils3 = require("@walletconnect/utils");
|
|
37
40
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
38
41
|
var _ethereumjsTx = require("ethereumjs-tx");
|
|
39
42
|
var _types2 = require("@polkadot/types");
|
|
@@ -519,7 +522,7 @@ class KoniExtension {
|
|
|
519
522
|
const account = _uiKeyring.keyring.getAccount(address);
|
|
520
523
|
const contact = _uiKeyring.keyring.getAddress(address);
|
|
521
524
|
return account || contact || {
|
|
522
|
-
..._uiKeyring.keyring.saveRecent(
|
|
525
|
+
..._uiKeyring.keyring.saveRecent(address).json,
|
|
523
526
|
publicKey: (0, _utilCrypto.decodeAddress)(address)
|
|
524
527
|
};
|
|
525
528
|
} else {
|
|
@@ -3096,6 +3099,138 @@ class KoniExtension {
|
|
|
3096
3099
|
return await this.#koniState.approvePassPhishingPage(url);
|
|
3097
3100
|
}
|
|
3098
3101
|
|
|
3102
|
+
/// Wallet connect
|
|
3103
|
+
|
|
3104
|
+
// Connect
|
|
3105
|
+
async connectWalletConnect(_ref75) {
|
|
3106
|
+
let {
|
|
3107
|
+
uri
|
|
3108
|
+
} = _ref75;
|
|
3109
|
+
await this.#koniState.walletConnectService.connect(uri);
|
|
3110
|
+
return true;
|
|
3111
|
+
}
|
|
3112
|
+
connectWCSubscribe(id, port) {
|
|
3113
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
3114
|
+
const subscription = this.#koniState.requestService.connectWCSubject.subscribe(requests => cb(requests));
|
|
3115
|
+
port.onDisconnect.addListener(() => {
|
|
3116
|
+
this.cancelSubscription(id);
|
|
3117
|
+
subscription.unsubscribe();
|
|
3118
|
+
});
|
|
3119
|
+
return this.#koniState.requestService.allConnectWCRequests;
|
|
3120
|
+
}
|
|
3121
|
+
async approveWalletConnectSession(_ref76) {
|
|
3122
|
+
let {
|
|
3123
|
+
accounts: selectedAccounts,
|
|
3124
|
+
id
|
|
3125
|
+
} = _ref76;
|
|
3126
|
+
const request = this.#koniState.requestService.getConnectWCRequest(id);
|
|
3127
|
+
if ((0, _helpers2.isProposalExpired)(request.request.params)) {
|
|
3128
|
+
throw new Error('The proposal has been expired');
|
|
3129
|
+
}
|
|
3130
|
+
const wcId = request.request.id;
|
|
3131
|
+
const params = request.request.params;
|
|
3132
|
+
const requiredNamespaces = params.requiredNamespaces;
|
|
3133
|
+
const optionalNamespaces = params.optionalNamespaces;
|
|
3134
|
+
const availableNamespaces = {};
|
|
3135
|
+
const namespaces = {};
|
|
3136
|
+
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
3137
|
+
Object.entries(requiredNamespaces).forEach(_ref77 => {
|
|
3138
|
+
let [key, namespace] = _ref77;
|
|
3139
|
+
if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
|
|
3140
|
+
if (namespace.chains) {
|
|
3141
|
+
const unSupportChains = namespace.chains.filter(chain => !(0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap));
|
|
3142
|
+
if (unSupportChains.length) {
|
|
3143
|
+
throw new Error((0, _utils3.getSdkError)('UNSUPPORTED_CHAINS').message + ' ' + unSupportChains.toString());
|
|
3144
|
+
}
|
|
3145
|
+
availableNamespaces[key] = namespace;
|
|
3146
|
+
}
|
|
3147
|
+
} else {
|
|
3148
|
+
throw new Error((0, _utils3.getSdkError)('UNSUPPORTED_NAMESPACE_KEY').message + ' ' + key);
|
|
3149
|
+
}
|
|
3150
|
+
});
|
|
3151
|
+
Object.entries(optionalNamespaces).forEach(_ref78 => {
|
|
3152
|
+
let [key, namespace] = _ref78;
|
|
3153
|
+
if ((0, _helpers2.isSupportWalletConnectNamespace)(key)) {
|
|
3154
|
+
if (namespace.chains) {
|
|
3155
|
+
const supportChains = namespace.chains.filter(chain => (0, _helpers2.isSupportWalletConnectChain)(chain, chainInfoMap)) || [];
|
|
3156
|
+
const requiredNameSpace = availableNamespaces[key];
|
|
3157
|
+
const defaultChains = [];
|
|
3158
|
+
if (requiredNameSpace) {
|
|
3159
|
+
availableNamespaces[key] = {
|
|
3160
|
+
chains: [...(requiredNameSpace.chains || defaultChains), ...(supportChains || defaultChains)],
|
|
3161
|
+
events: requiredNameSpace.events,
|
|
3162
|
+
methods: requiredNameSpace.methods
|
|
3163
|
+
};
|
|
3164
|
+
} else {
|
|
3165
|
+
if (supportChains.length) {
|
|
3166
|
+
availableNamespaces[key] = {
|
|
3167
|
+
chains: supportChains,
|
|
3168
|
+
events: namespace.events,
|
|
3169
|
+
methods: namespace.methods
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
}
|
|
3175
|
+
});
|
|
3176
|
+
Object.entries(availableNamespaces).forEach(_ref79 => {
|
|
3177
|
+
let [key, namespace] = _ref79;
|
|
3178
|
+
if (namespace.chains) {
|
|
3179
|
+
const accounts = [];
|
|
3180
|
+
const chains = (0, _utils2.uniqueStringArray)(namespace.chains);
|
|
3181
|
+
chains.forEach(chain => {
|
|
3182
|
+
accounts.push(...selectedAccounts.filter(address => (0, _utilCrypto.isEthereumAddress)(address) === (key === _constants4.WALLET_CONNECT_EIP155_NAMESPACE)).map(address => `${chain}:${address}`));
|
|
3183
|
+
});
|
|
3184
|
+
namespaces[key] = {
|
|
3185
|
+
accounts,
|
|
3186
|
+
methods: namespace.methods,
|
|
3187
|
+
events: namespace.events,
|
|
3188
|
+
chains: chains
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
});
|
|
3192
|
+
const result = {
|
|
3193
|
+
id: wcId,
|
|
3194
|
+
namespaces: namespaces,
|
|
3195
|
+
relayProtocol: params.relays[0].protocol
|
|
3196
|
+
};
|
|
3197
|
+
await this.#koniState.walletConnectService.approveSession(result);
|
|
3198
|
+
request.resolve();
|
|
3199
|
+
return true;
|
|
3200
|
+
}
|
|
3201
|
+
async rejectWalletConnectSession(_ref80) {
|
|
3202
|
+
let {
|
|
3203
|
+
id
|
|
3204
|
+
} = _ref80;
|
|
3205
|
+
const request = this.#koniState.requestService.getConnectWCRequest(id);
|
|
3206
|
+
const wcId = request.request.id;
|
|
3207
|
+
if ((0, _helpers2.isProposalExpired)(request.request.params)) {
|
|
3208
|
+
request.reject(new Error('The proposal has been expired'));
|
|
3209
|
+
return true;
|
|
3210
|
+
}
|
|
3211
|
+
await this.#koniState.walletConnectService.rejectSession(wcId);
|
|
3212
|
+
request.reject(new Error('USER_REJECTED'));
|
|
3213
|
+
return true;
|
|
3214
|
+
}
|
|
3215
|
+
subscribeWalletConnectSessions(id, port) {
|
|
3216
|
+
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
3217
|
+
const subscription = this.#koniState.walletConnectService.sessionSubject.subscribe(rs => {
|
|
3218
|
+
cb(rs);
|
|
3219
|
+
});
|
|
3220
|
+
port.onDisconnect.addListener(() => {
|
|
3221
|
+
subscription.unsubscribe();
|
|
3222
|
+
this.cancelSubscription(id);
|
|
3223
|
+
});
|
|
3224
|
+
return this.#koniState.walletConnectService.sessions;
|
|
3225
|
+
}
|
|
3226
|
+
async disconnectWalletConnectSession(_ref81) {
|
|
3227
|
+
let {
|
|
3228
|
+
topic
|
|
3229
|
+
} = _ref81;
|
|
3230
|
+
await this.#koniState.walletConnectService.disconnect(topic);
|
|
3231
|
+
return true;
|
|
3232
|
+
}
|
|
3233
|
+
|
|
3099
3234
|
// --------------------------------------------------------------
|
|
3100
3235
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3101
3236
|
async handle(id, type, request, port) {
|
|
@@ -3469,6 +3604,20 @@ class KoniExtension {
|
|
|
3469
3604
|
case 'pri(settings.getLogoMaps)':
|
|
3470
3605
|
return await this.getLogoMap();
|
|
3471
3606
|
|
|
3607
|
+
/// Wallet Connect
|
|
3608
|
+
case 'pri(walletConnect.connect)':
|
|
3609
|
+
return this.connectWalletConnect(request);
|
|
3610
|
+
case 'pri(walletConnect.requests.subscribe)':
|
|
3611
|
+
return this.connectWCSubscribe(id, port);
|
|
3612
|
+
case 'pri(walletConnect.session.approve)':
|
|
3613
|
+
return this.approveWalletConnectSession(request);
|
|
3614
|
+
case 'pri(walletConnect.session.reject)':
|
|
3615
|
+
return this.rejectWalletConnectSession(request);
|
|
3616
|
+
case 'pri(walletConnect.session.subscribe)':
|
|
3617
|
+
return this.subscribeWalletConnectSessions(id, port);
|
|
3618
|
+
case 'pri(walletConnect.session.disconnect)':
|
|
3619
|
+
return this.disconnectWalletConnectSession(request);
|
|
3620
|
+
|
|
3472
3621
|
// Default
|
|
3473
3622
|
default:
|
|
3474
3623
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
@@ -28,7 +28,9 @@ var _DatabaseService = _interopRequireDefault(require("@subwallet/extension-base
|
|
|
28
28
|
var _subscanService = require("@subwallet/extension-base/services/subscan-service");
|
|
29
29
|
var _subscanChainMap = require("@subwallet/extension-base/services/subscan-service/subscan-chain-map");
|
|
30
30
|
var _transactionService = _interopRequireDefault(require("@subwallet/extension-base/services/transaction-service"));
|
|
31
|
+
var _walletConnectService = _interopRequireDefault(require("@subwallet/extension-base/services/wallet-connect-service"));
|
|
31
32
|
var _AccountRef = _interopRequireDefault(require("@subwallet/extension-base/stores/AccountRef"));
|
|
33
|
+
var _utils2 = require("@subwallet/extension-base/utils");
|
|
32
34
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
33
35
|
var _promise = require("@subwallet/extension-base/utils/promise");
|
|
34
36
|
var _decode = require("@subwallet/keyring/pair/decode");
|
|
@@ -101,6 +103,7 @@ class KoniState {
|
|
|
101
103
|
this.balanceService = new _balanceService.BalanceService(this.chainService);
|
|
102
104
|
this.historyService = new _historyService.HistoryService(this.dbService, this.chainService, this.eventService, this.keyringService);
|
|
103
105
|
this.transactionService = new _transactionService.default(this.chainService, this.eventService, this.requestService, this.balanceService, this.historyService, this.notificationService, this.dbService);
|
|
106
|
+
this.walletConnectService = new _walletConnectService.default(this, this.requestService);
|
|
104
107
|
this.migrationService = new _migrationService.default(this);
|
|
105
108
|
this.subscription = new _subscription.KoniSubscription(this, this.dbService);
|
|
106
109
|
this.cron = new _cron.KoniCron(this, this.subscription, this.dbService);
|
|
@@ -1273,9 +1276,10 @@ class KoniState {
|
|
|
1273
1276
|
const transactionData = {
|
|
1274
1277
|
...transaction
|
|
1275
1278
|
};
|
|
1279
|
+
const token = this.chainService.getNativeTokenInfo(networkKey);
|
|
1276
1280
|
if (eType === _KoniTypes.ExtrinsicType.TRANSFER_BALANCE) {
|
|
1277
1281
|
// @ts-ignore
|
|
1278
|
-
transactionData.tokenSlug =
|
|
1282
|
+
transactionData.tokenSlug = token.slug;
|
|
1279
1283
|
}
|
|
1280
1284
|
|
|
1281
1285
|
// Custom handle this instead of general handler transaction
|
|
@@ -1286,7 +1290,13 @@ class KoniState {
|
|
|
1286
1290
|
url,
|
|
1287
1291
|
data: transactionData,
|
|
1288
1292
|
extrinsicType: eType,
|
|
1289
|
-
chainType: _KoniTypes.ChainType.EVM
|
|
1293
|
+
chainType: _KoniTypes.ChainType.EVM,
|
|
1294
|
+
estimateFee: {
|
|
1295
|
+
value: estimateGas,
|
|
1296
|
+
symbol: token.symbol,
|
|
1297
|
+
decimals: token.decimals || 18
|
|
1298
|
+
},
|
|
1299
|
+
id
|
|
1290
1300
|
});
|
|
1291
1301
|
|
|
1292
1302
|
// Wait extrinsic hash
|
|
@@ -1534,7 +1544,7 @@ class KoniState {
|
|
|
1534
1544
|
const result = {
|
|
1535
1545
|
...value
|
|
1536
1546
|
};
|
|
1537
|
-
const url =
|
|
1547
|
+
const url = (0, _utils2.stripUrl)(_url);
|
|
1538
1548
|
result[url] = {
|
|
1539
1549
|
pass: true
|
|
1540
1550
|
};
|
|
@@ -1554,6 +1564,7 @@ class KoniState {
|
|
|
1554
1564
|
this.settingService.resetWallet();
|
|
1555
1565
|
}
|
|
1556
1566
|
this.chainService.resetWallet(resetAll);
|
|
1567
|
+
await this.walletConnectService.resetWallet(resetAll);
|
|
1557
1568
|
await this.chainService.init();
|
|
1558
1569
|
}
|
|
1559
1570
|
}
|