@subwallet/extension-base 1.1.4-0 → 1.1.6-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 +14 -4
- package/background/types.d.ts +4 -0
- package/cjs/koni/api/nft/config.js +12 -9
- package/cjs/koni/background/handlers/Extension.js +49 -11
- package/cjs/koni/background/handlers/Tabs.js +65 -31
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Accounts.js +7 -2
- package/cjs/page/Injected.js +5 -0
- package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -2
- package/cjs/services/request-service/handler/{WalletConnectRequestHandler.js → ConnectWCRequestHandler.js} +9 -9
- package/cjs/services/request-service/handler/NotSupportWCRequestHandler.js +71 -0
- package/cjs/services/request-service/handler/index.js +55 -0
- package/cjs/services/request-service/index.js +36 -22
- package/cjs/services/transaction-service/index.js +5 -1
- package/cjs/services/wallet-connect-service/helpers.js +10 -1
- package/cjs/services/wallet-connect-service/index.js +5 -0
- package/koni/api/nft/config.js +12 -9
- package/koni/background/handlers/Extension.d.ts +4 -1
- package/koni/background/handlers/Extension.js +43 -7
- package/koni/background/handlers/Tabs.d.ts +3 -1
- package/koni/background/handlers/Tabs.js +44 -11
- package/package.json +22 -12
- package/packageInfo.js +1 -1
- package/page/Accounts.js +7 -2
- package/page/Injected.js +5 -0
- package/services/request-service/handler/AuthRequestHandler.d.ts +3 -3
- package/services/request-service/handler/AuthRequestHandler.js +5 -3
- package/services/request-service/handler/{WalletConnectRequestHandler.d.ts → ConnectWCRequestHandler.d.ts} +1 -1
- package/services/request-service/handler/{WalletConnectRequestHandler.js → ConnectWCRequestHandler.js} +8 -8
- package/services/request-service/handler/NotSupportWCRequestHandler.d.ts +15 -0
- package/services/request-service/handler/NotSupportWCRequestHandler.js +62 -0
- package/services/request-service/handler/index.d.ts +7 -0
- package/services/request-service/handler/index.js +10 -0
- package/services/request-service/index.d.ts +11 -6
- package/services/request-service/index.js +31 -16
- package/services/transaction-service/index.js +5 -1
- package/services/wallet-connect-service/helpers.d.ts +2 -1
- package/services/wallet-connect-service/helpers.js +8 -0
- package/services/wallet-connect-service/index.js +6 -1
- package/services/wallet-connect-service/types.d.ts +5 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "AuthRequestHandler", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _AuthRequestHandler.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "ConnectWCRequestHandler", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _ConnectWCRequestHandler.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "EvmRequestHandler", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _EvmRequestHandler.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "MetadataRequestHandler", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _MetadataRequestHandler.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "NotSupportWCRequestHandler", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _NotSupportWCRequestHandler.default;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "PopupHandler", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _PopupHandler.default;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "SubstrateRequestHandler", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _SubstrateRequestHandler.default;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var _AuthRequestHandler = _interopRequireDefault(require("./AuthRequestHandler"));
|
|
50
|
+
var _ConnectWCRequestHandler = _interopRequireDefault(require("./ConnectWCRequestHandler"));
|
|
51
|
+
var _EvmRequestHandler = _interopRequireDefault(require("./EvmRequestHandler"));
|
|
52
|
+
var _MetadataRequestHandler = _interopRequireDefault(require("./MetadataRequestHandler"));
|
|
53
|
+
var _NotSupportWCRequestHandler = _interopRequireDefault(require("./NotSupportWCRequestHandler"));
|
|
54
|
+
var _PopupHandler = _interopRequireDefault(require("./PopupHandler"));
|
|
55
|
+
var _SubstrateRequestHandler = _interopRequireDefault(require("./SubstrateRequestHandler"));
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
|
-
var
|
|
9
|
-
var _EvmRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/EvmRequestHandler"));
|
|
10
|
-
var _MetadataRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/MetadataRequestHandler"));
|
|
11
|
-
var _PopupHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/PopupHandler"));
|
|
12
|
-
var _SubstrateRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/SubstrateRequestHandler"));
|
|
13
|
-
var _WalletConnectRequestHandler = _interopRequireDefault(require("@subwallet/extension-base/services/request-service/handler/WalletConnectRequestHandler"));
|
|
7
|
+
var _handler = require("./handler");
|
|
14
8
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
15
9
|
// SPDX-License-Identifier: Apache-2.0
|
|
16
10
|
|
|
@@ -22,19 +16,21 @@ class RequestService {
|
|
|
22
16
|
#authRequestHandler;
|
|
23
17
|
#substrateRequestHandler;
|
|
24
18
|
#evmRequestHandler;
|
|
25
|
-
#
|
|
19
|
+
#connectWCRequestHandler;
|
|
20
|
+
#notSupportWCRequestHandler;
|
|
26
21
|
|
|
27
22
|
// Common
|
|
28
23
|
constructor(chainService, settingService, keyringService) {
|
|
29
24
|
this.keyringService = keyringService;
|
|
30
25
|
this.#chainService = chainService;
|
|
31
26
|
this.settingService = settingService;
|
|
32
|
-
this.#popupHandler = new
|
|
33
|
-
this.#metadataRequestHandler = new
|
|
34
|
-
this.#authRequestHandler = new
|
|
35
|
-
this.#substrateRequestHandler = new
|
|
36
|
-
this.#evmRequestHandler = new
|
|
37
|
-
this.#
|
|
27
|
+
this.#popupHandler = new _handler.PopupHandler(this);
|
|
28
|
+
this.#metadataRequestHandler = new _handler.MetadataRequestHandler(this);
|
|
29
|
+
this.#authRequestHandler = new _handler.AuthRequestHandler(this, this.#chainService, this.keyringService);
|
|
30
|
+
this.#substrateRequestHandler = new _handler.SubstrateRequestHandler(this);
|
|
31
|
+
this.#evmRequestHandler = new _handler.EvmRequestHandler(this);
|
|
32
|
+
this.#connectWCRequestHandler = new _handler.ConnectWCRequestHandler(this);
|
|
33
|
+
this.#notSupportWCRequestHandler = new _handler.NotSupportWCRequestHandler(this);
|
|
38
34
|
|
|
39
35
|
// Reset icon on start service
|
|
40
36
|
this.updateIconV2();
|
|
@@ -170,33 +166,51 @@ class RequestService {
|
|
|
170
166
|
return this.#evmRequestHandler.updateConfirmation(id, type, payload, options, validator);
|
|
171
167
|
}
|
|
172
168
|
|
|
173
|
-
//
|
|
169
|
+
// WalletConnect Connect requests
|
|
174
170
|
getConnectWCRequest(id) {
|
|
175
|
-
return this.#
|
|
171
|
+
return this.#connectWCRequestHandler.getConnectWCRequest(id);
|
|
176
172
|
}
|
|
177
173
|
get connectWCSubject() {
|
|
178
|
-
return this.#
|
|
174
|
+
return this.#connectWCRequestHandler.connectWCSubject;
|
|
179
175
|
}
|
|
180
176
|
get allConnectWCRequests() {
|
|
181
|
-
return this.#
|
|
177
|
+
return this.#connectWCRequestHandler.allConnectWCRequests;
|
|
182
178
|
}
|
|
183
179
|
get numConnectWCRequests() {
|
|
184
|
-
return this.#
|
|
180
|
+
return this.#connectWCRequestHandler.numConnectWCRequests;
|
|
185
181
|
}
|
|
186
182
|
addConnectWCRequest(request) {
|
|
187
|
-
return this.#
|
|
183
|
+
return this.#connectWCRequestHandler.addConnectWCRequest(request);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// WalletConnect not support requests
|
|
187
|
+
getNotSupportWCRequest(id) {
|
|
188
|
+
return this.#notSupportWCRequestHandler.getNotSupportWCRequest(id);
|
|
189
|
+
}
|
|
190
|
+
get notSupportWCSubject() {
|
|
191
|
+
return this.#notSupportWCRequestHandler.notSupportWCSubject;
|
|
192
|
+
}
|
|
193
|
+
get allNotSupportWCRequests() {
|
|
194
|
+
return this.#notSupportWCRequestHandler.allNotSupportWCRequests;
|
|
195
|
+
}
|
|
196
|
+
get numNotSupportWCRequests() {
|
|
197
|
+
return this.#notSupportWCRequestHandler.numNotSupportWCRequests;
|
|
198
|
+
}
|
|
199
|
+
addNotSupportWCRequest(request) {
|
|
200
|
+
return this.#notSupportWCRequestHandler.addNotSupportWCRequest(request);
|
|
188
201
|
}
|
|
189
202
|
|
|
190
203
|
// General methods
|
|
191
204
|
get numRequests() {
|
|
192
|
-
return this.numMetaRequests + this.numAuthRequests + this.numSubstrateRequests + this.numEvmRequests + this.numConnectWCRequests;
|
|
205
|
+
return this.numMetaRequests + this.numAuthRequests + this.numSubstrateRequests + this.numEvmRequests + this.numConnectWCRequests + this.numNotSupportWCRequests;
|
|
193
206
|
}
|
|
194
207
|
resetWallet() {
|
|
195
208
|
this.#authRequestHandler.resetWallet();
|
|
196
209
|
this.#substrateRequestHandler.resetWallet();
|
|
197
210
|
this.#evmRequestHandler.resetWallet();
|
|
198
211
|
this.#metadataRequestHandler.resetWallet();
|
|
199
|
-
this.#
|
|
212
|
+
this.#connectWCRequestHandler.resetWallet();
|
|
213
|
+
this.#notSupportWCRequestHandler.resetWallet();
|
|
200
214
|
}
|
|
201
215
|
}
|
|
202
216
|
exports.default = RequestService;
|
|
@@ -22,6 +22,7 @@ var _eth = require("@subwallet/extension-base/utils/eth");
|
|
|
22
22
|
var _mergeTransactionAndSignature = require("@subwallet/extension-base/utils/eth/mergeTransactionAndSignature");
|
|
23
23
|
var _parseTransaction = require("@subwallet/extension-base/utils/eth/parseTransaction");
|
|
24
24
|
var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
|
|
25
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
25
26
|
var _ethereumjsUtil = require("ethereumjs-util");
|
|
26
27
|
var _ethers = require("ethers");
|
|
27
28
|
var _eventemitter = _interopRequireDefault(require("eventemitter3"));
|
|
@@ -120,7 +121,7 @@ class TransactionService {
|
|
|
120
121
|
}
|
|
121
122
|
} catch (e) {
|
|
122
123
|
const error = e;
|
|
123
|
-
if (error.message.includes('gas required exceeds allowance')) {
|
|
124
|
+
if (error.message.includes('gas required exceeds allowance') && error.message.includes('insufficient funds')) {
|
|
124
125
|
validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
125
126
|
}
|
|
126
127
|
estimateFee.value = '0';
|
|
@@ -149,6 +150,9 @@ class TransactionService {
|
|
|
149
150
|
const balanceNum = parseInt(balance.value);
|
|
150
151
|
const edNum = parseInt(existentialDeposit);
|
|
151
152
|
const transferNativeNum = parseInt(transferNative);
|
|
153
|
+
if (!new _bignumber.default(balance.value).gt(0)) {
|
|
154
|
+
validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
155
|
+
}
|
|
152
156
|
if (transferNativeNum + feeNum > balanceNum) {
|
|
153
157
|
if (!isTransferAll) {
|
|
154
158
|
validationResponse.errors.push(new _TransactionError.TransactionError(_KoniTypes.BasicTxErrorType.NOT_ENOUGH_BALANCE));
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.parseRequestParams = exports.isWalletConnectRequest = exports.isSupportWalletConnectNamespace = exports.isSupportWalletConnectChain = exports.isProposalExpired = exports.getWCId = exports.getEip155MessageAddress = exports.convertConnectRequest = void 0;
|
|
6
|
+
exports.parseRequestParams = exports.isWalletConnectRequest = exports.isSupportWalletConnectNamespace = exports.isSupportWalletConnectChain = exports.isProposalExpired = exports.getWCId = exports.getEip155MessageAddress = exports.convertNotSupportRequest = exports.convertConnectRequest = void 0;
|
|
7
7
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
8
8
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
9
9
|
var _constants = require("./constants");
|
|
@@ -24,6 +24,15 @@ const convertConnectRequest = request => {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
exports.convertConnectRequest = convertConnectRequest;
|
|
27
|
+
const convertNotSupportRequest = (request, url) => {
|
|
28
|
+
return {
|
|
29
|
+
id: getWCId(request.id),
|
|
30
|
+
isInternal: false,
|
|
31
|
+
request: request,
|
|
32
|
+
url: url
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.convertNotSupportRequest = convertNotSupportRequest;
|
|
27
36
|
const parseRequestParams = params => {
|
|
28
37
|
// @ts-ignore
|
|
29
38
|
return params;
|
|
@@ -259,6 +259,11 @@ function _onSessionRequest2(requestEvent) {
|
|
|
259
259
|
}
|
|
260
260
|
} catch (e) {
|
|
261
261
|
console.log(e);
|
|
262
|
+
try {
|
|
263
|
+
const requestSession = this.getSession(topic);
|
|
264
|
+
const notSupportRequest = (0, _helpers.convertNotSupportRequest)(requestEvent, requestSession.peer.metadata.url);
|
|
265
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _requestService)[_requestService].addNotSupportWCRequest(notSupportRequest);
|
|
266
|
+
} catch (e) {}
|
|
262
267
|
this.responseRequest({
|
|
263
268
|
topic: topic,
|
|
264
269
|
response: (0, _utils.formatJsonRpcError)(id, e.message)
|
package/koni/api/nft/config.js
CHANGED
|
@@ -68,9 +68,6 @@ export let SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME;
|
|
|
68
68
|
SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME["pioneer"] = "pioneer";
|
|
69
69
|
})(SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME || (SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = {}));
|
|
70
70
|
const RANDOM_IPFS_GATEWAY_SETTING = [{
|
|
71
|
-
provider: IPFS_W3S_LINK,
|
|
72
|
-
weight: 1
|
|
73
|
-
}, {
|
|
74
71
|
provider: CF_IPFS_GATEWAY,
|
|
75
72
|
weight: 4
|
|
76
73
|
}, {
|
|
@@ -85,12 +82,6 @@ const RANDOM_IPFS_GATEWAY_SETTING = [{
|
|
|
85
82
|
}, {
|
|
86
83
|
provider: DWEB_LINK,
|
|
87
84
|
weight: 5
|
|
88
|
-
}, {
|
|
89
|
-
provider: IPFS_GATEWAY_4EVERLAND,
|
|
90
|
-
weight: 2
|
|
91
|
-
}, {
|
|
92
|
-
provider: IPFS_HARDBIN,
|
|
93
|
-
weight: 1
|
|
94
85
|
}];
|
|
95
86
|
if (!RuntimeInfo.protocol || RuntimeInfo.protocol && !RuntimeInfo.protocol.startsWith('http')) {
|
|
96
87
|
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
@@ -101,6 +92,18 @@ if (!RuntimeInfo.protocol || RuntimeInfo.protocol && !RuntimeInfo.protocol.start
|
|
|
101
92
|
provider: IPFS_FLEEK,
|
|
102
93
|
weight: 4
|
|
103
94
|
});
|
|
95
|
+
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
96
|
+
provider: IPFS_HARDBIN,
|
|
97
|
+
weight: 1
|
|
98
|
+
});
|
|
99
|
+
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
100
|
+
provider: IPFS_GATEWAY_4EVERLAND,
|
|
101
|
+
weight: 2
|
|
102
|
+
});
|
|
103
|
+
RANDOM_IPFS_GATEWAY_SETTING.push({
|
|
104
|
+
provider: IPFS_W3S_LINK,
|
|
105
|
+
weight: 1
|
|
106
|
+
});
|
|
104
107
|
}
|
|
105
108
|
const RANDOM_IPFS_GATEWAY_TOTAL_WEIGHT = RANDOM_IPFS_GATEWAY_SETTING.reduce((value, item) => value + item.weight, 0);
|
|
106
109
|
export function getRandomIpfsGateway() {
|
|
@@ -53,7 +53,7 @@ export default class KoniExtension {
|
|
|
53
53
|
private forgetSite;
|
|
54
54
|
private _forgetAllSite;
|
|
55
55
|
private forgetAllSite;
|
|
56
|
-
private
|
|
56
|
+
private getAccounts;
|
|
57
57
|
private isAddressValidWithAuthType;
|
|
58
58
|
private filterAccountsByAccountAuthType;
|
|
59
59
|
private _changeAuthorizationAll;
|
|
@@ -197,6 +197,9 @@ export default class KoniExtension {
|
|
|
197
197
|
private rejectWalletConnectSession;
|
|
198
198
|
private subscribeWalletConnectSessions;
|
|
199
199
|
private disconnectWalletConnectSession;
|
|
200
|
+
private WCNotSupportSubscribe;
|
|
201
|
+
private approveWalletConnectNotSupport;
|
|
202
|
+
private rejectWalletConnectNotSupport;
|
|
200
203
|
private enableMantaPay;
|
|
201
204
|
private initSyncMantaPay;
|
|
202
205
|
private disableMantaPay;
|
|
@@ -660,10 +660,10 @@ export default class KoniExtension {
|
|
|
660
660
|
});
|
|
661
661
|
return true;
|
|
662
662
|
}
|
|
663
|
-
|
|
663
|
+
getAccounts() {
|
|
664
664
|
const storedAccounts = this.#koniState.keyringService.accounts;
|
|
665
665
|
const transformedAccounts = transformAccounts(storedAccounts);
|
|
666
|
-
return transformedAccounts.
|
|
666
|
+
return transformedAccounts.map(a => a.address);
|
|
667
667
|
}
|
|
668
668
|
isAddressValidWithAuthType(address, accountAuthType) {
|
|
669
669
|
if (accountAuthType === 'substrate') {
|
|
@@ -685,12 +685,12 @@ export default class KoniExtension {
|
|
|
685
685
|
_changeAuthorizationAll(connectValue, callBack) {
|
|
686
686
|
this.#koniState.getAuthorize(value => {
|
|
687
687
|
assert(value, 'The source is not known');
|
|
688
|
-
const
|
|
688
|
+
const accounts = this.getAccounts();
|
|
689
689
|
Object.keys(value).forEach(url => {
|
|
690
690
|
if (!value[url].isAllowed) {
|
|
691
691
|
return;
|
|
692
692
|
}
|
|
693
|
-
const targetAccounts = this.filterAccountsByAccountAuthType(
|
|
693
|
+
const targetAccounts = this.filterAccountsByAccountAuthType(accounts, value[url].accountAuthType);
|
|
694
694
|
targetAccounts.forEach(address => {
|
|
695
695
|
value[url].isAllowedMap[address] = connectValue;
|
|
696
696
|
});
|
|
@@ -713,8 +713,8 @@ export default class KoniExtension {
|
|
|
713
713
|
_changeAuthorization(url, connectValue, callBack) {
|
|
714
714
|
this.#koniState.getAuthorize(value => {
|
|
715
715
|
assert(value[url], 'The source is not known');
|
|
716
|
-
const
|
|
717
|
-
const targetAccounts = this.filterAccountsByAccountAuthType(
|
|
716
|
+
const accounts = this.getAccounts();
|
|
717
|
+
const targetAccounts = this.filterAccountsByAccountAuthType(accounts, value[url].accountAuthType);
|
|
718
718
|
targetAccounts.forEach(address => {
|
|
719
719
|
value[url].isAllowedMap[address] = connectValue;
|
|
720
720
|
});
|
|
@@ -3219,6 +3219,32 @@ export default class KoniExtension {
|
|
|
3219
3219
|
await this.#koniState.walletConnectService.disconnect(topic);
|
|
3220
3220
|
return true;
|
|
3221
3221
|
}
|
|
3222
|
+
WCNotSupportSubscribe(id, port) {
|
|
3223
|
+
const cb = createSubscription(id, port);
|
|
3224
|
+
const subscription = this.#koniState.requestService.notSupportWCSubject.subscribe(requests => cb(requests));
|
|
3225
|
+
port.onDisconnect.addListener(() => {
|
|
3226
|
+
this.cancelSubscription(id);
|
|
3227
|
+
subscription.unsubscribe();
|
|
3228
|
+
});
|
|
3229
|
+
return this.#koniState.requestService.allNotSupportWCRequests;
|
|
3230
|
+
}
|
|
3231
|
+
approveWalletConnectNotSupport({
|
|
3232
|
+
id
|
|
3233
|
+
}) {
|
|
3234
|
+
const request = this.#koniState.requestService.getNotSupportWCRequest(id);
|
|
3235
|
+
request.resolve();
|
|
3236
|
+
return true;
|
|
3237
|
+
}
|
|
3238
|
+
rejectWalletConnectNotSupport({
|
|
3239
|
+
id
|
|
3240
|
+
}) {
|
|
3241
|
+
const request = this.#koniState.requestService.getNotSupportWCRequest(id);
|
|
3242
|
+
request.reject(new Error('USER_REJECTED'));
|
|
3243
|
+
return true;
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
/// Manta
|
|
3247
|
+
|
|
3222
3248
|
async enableMantaPay({
|
|
3223
3249
|
address,
|
|
3224
3250
|
password
|
|
@@ -3743,7 +3769,7 @@ export default class KoniExtension {
|
|
|
3743
3769
|
/// Wallet Connect
|
|
3744
3770
|
case 'pri(walletConnect.connect)':
|
|
3745
3771
|
return this.connectWalletConnect(request);
|
|
3746
|
-
case 'pri(walletConnect.requests.subscribe)':
|
|
3772
|
+
case 'pri(walletConnect.requests.connect.subscribe)':
|
|
3747
3773
|
return this.connectWCSubscribe(id, port);
|
|
3748
3774
|
case 'pri(walletConnect.session.approve)':
|
|
3749
3775
|
return this.approveWalletConnectSession(request);
|
|
@@ -3753,6 +3779,16 @@ export default class KoniExtension {
|
|
|
3753
3779
|
return this.subscribeWalletConnectSessions(id, port);
|
|
3754
3780
|
case 'pri(walletConnect.session.disconnect)':
|
|
3755
3781
|
return this.disconnectWalletConnectSession(request);
|
|
3782
|
+
|
|
3783
|
+
// Not support
|
|
3784
|
+
case 'pri(walletConnect.requests.notSupport.subscribe)':
|
|
3785
|
+
return this.WCNotSupportSubscribe(id, port);
|
|
3786
|
+
case 'pri(walletConnect.notSupport.approve)':
|
|
3787
|
+
return this.approveWalletConnectNotSupport(request);
|
|
3788
|
+
case 'pri(walletConnect.notSupport.reject)':
|
|
3789
|
+
return this.rejectWalletConnectNotSupport(request);
|
|
3790
|
+
|
|
3791
|
+
// Manta
|
|
3756
3792
|
case 'pri(mantaPay.enable)':
|
|
3757
3793
|
return await this.enableMantaPay(request);
|
|
3758
3794
|
case 'pri(mantaPay.initSyncMantaPay)':
|
|
@@ -3,6 +3,7 @@ import { AuthUrlInfo } from '@subwallet/extension-base/background/handlers/State
|
|
|
3
3
|
import { RequestAddPspToken } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { MessageTypes, RequestTypes, ResponseTypes } from '@subwallet/extension-base/background/types';
|
|
5
5
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
6
|
+
import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
|
|
6
7
|
import { RequestArguments } from 'web3-core';
|
|
7
8
|
export declare const chainPatrolCheckUrl: (url: string) => Promise<boolean>;
|
|
8
9
|
export default class KoniTabs {
|
|
@@ -26,9 +27,10 @@ export default class KoniTabs {
|
|
|
26
27
|
protected redirectIfPhishing(url: string): Promise<boolean>;
|
|
27
28
|
private cancelSubscription;
|
|
28
29
|
private createUnsubscriptionHandle;
|
|
29
|
-
getAuthInfo(url: string): Promise<AuthUrlInfo | undefined>;
|
|
30
|
+
getAuthInfo(url: string, fromList?: AuthUrls): Promise<AuthUrlInfo | undefined>;
|
|
30
31
|
private accountsListV2;
|
|
31
32
|
private accountsSubscribeV2;
|
|
33
|
+
private accountsUnsubscribe;
|
|
32
34
|
private authorizeV2;
|
|
33
35
|
private getEvmCurrentAccount;
|
|
34
36
|
private getEvmState;
|
|
@@ -77,6 +77,7 @@ export const chainPatrolCheckUrl = async url => {
|
|
|
77
77
|
return data.status === 'BLOCKED';
|
|
78
78
|
};
|
|
79
79
|
export default class KoniTabs {
|
|
80
|
+
#accountSubs = {};
|
|
80
81
|
#koniState;
|
|
81
82
|
evmEventEmitterMap = {};
|
|
82
83
|
#chainPatrolService = DEFAULT_CHAIN_PATROL_ENABLE;
|
|
@@ -105,17 +106,25 @@ export default class KoniTabs {
|
|
|
105
106
|
assert(pair, 'Unable to find keypair');
|
|
106
107
|
return pair;
|
|
107
108
|
}
|
|
108
|
-
bytesSign(url, request) {
|
|
109
|
+
async bytesSign(url, request) {
|
|
109
110
|
const address = request.address;
|
|
110
111
|
const pair = this.getSigningPair(address);
|
|
112
|
+
const authInfo = await this.getAuthInfo(url);
|
|
113
|
+
if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[pair.address]) {
|
|
114
|
+
throw new Error('Account {{address}} not in allowed list'.replace('{{address}}', address));
|
|
115
|
+
}
|
|
111
116
|
return this.#koniState.sign(url, new RequestBytesSign(request), {
|
|
112
117
|
address,
|
|
113
118
|
...pair.meta
|
|
114
119
|
});
|
|
115
120
|
}
|
|
116
|
-
extrinsicSign(url, request) {
|
|
121
|
+
async extrinsicSign(url, request) {
|
|
117
122
|
const address = request.address;
|
|
118
123
|
const pair = this.getSigningPair(address);
|
|
124
|
+
const authInfo = await this.getAuthInfo(url);
|
|
125
|
+
if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[pair.address]) {
|
|
126
|
+
throw new Error('Account {{address}} not in allowed list'.replace('{{address}}', address));
|
|
127
|
+
}
|
|
119
128
|
return this.#koniState.sign(url, new RequestExtrinsicSign(request), {
|
|
120
129
|
address,
|
|
121
130
|
...pair.meta
|
|
@@ -217,8 +226,8 @@ export default class KoniTabs {
|
|
|
217
226
|
createUnsubscriptionHandle(id, unsubscribe) {
|
|
218
227
|
this.#koniState.createUnsubscriptionHandle(id, unsubscribe);
|
|
219
228
|
}
|
|
220
|
-
async getAuthInfo(url) {
|
|
221
|
-
const authList = await this.#koniState.getAuthList();
|
|
229
|
+
async getAuthInfo(url, fromList) {
|
|
230
|
+
const authList = fromList || (await this.#koniState.getAuthList());
|
|
222
231
|
const shortenUrl = stripUrl(url);
|
|
223
232
|
return authList[shortenUrl];
|
|
224
233
|
}
|
|
@@ -233,15 +242,35 @@ export default class KoniTabs {
|
|
|
233
242
|
accountAuthType
|
|
234
243
|
}, id, port) {
|
|
235
244
|
const cb = createSubscription(id, port);
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
245
|
+
const authInfoSubject = this.#koniState.requestService.subscribeAuthorizeUrlSubject;
|
|
246
|
+
|
|
247
|
+
// Update unsubscribe from @polkadot/extension-base
|
|
248
|
+
this.#accountSubs[id] = {
|
|
249
|
+
subscription: authInfoSubject.subscribe(infos => {
|
|
250
|
+
this.getAuthInfo(url, infos).then(authInfo => {
|
|
251
|
+
const accounts = this.#koniState.keyringService.accounts;
|
|
252
|
+
return cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
|
|
253
|
+
}).catch(console.error);
|
|
254
|
+
}),
|
|
255
|
+
url
|
|
256
|
+
};
|
|
242
257
|
port.onDisconnect.addListener(() => {
|
|
243
|
-
this.
|
|
258
|
+
this.accountsUnsubscribe(url, {
|
|
259
|
+
id
|
|
260
|
+
});
|
|
244
261
|
});
|
|
262
|
+
return id;
|
|
263
|
+
}
|
|
264
|
+
accountsUnsubscribe(url, {
|
|
265
|
+
id
|
|
266
|
+
}) {
|
|
267
|
+
const sub = this.#accountSubs[id];
|
|
268
|
+
if (!sub || sub.url !== url) {
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
271
|
+
delete this.#accountSubs[id];
|
|
272
|
+
unsubscribe(id);
|
|
273
|
+
sub.subscription.unsubscribe();
|
|
245
274
|
return true;
|
|
246
275
|
}
|
|
247
276
|
authorizeV2(url, request) {
|
|
@@ -897,6 +926,8 @@ export default class KoniTabs {
|
|
|
897
926
|
return this.metadataList(url);
|
|
898
927
|
case 'pub(metadata.provide)':
|
|
899
928
|
return this.metadataProvide(url, request);
|
|
929
|
+
case 'pub(ping)':
|
|
930
|
+
return Promise.resolve(true);
|
|
900
931
|
case 'pub(rpc.listProviders)':
|
|
901
932
|
return this.rpcListProviders();
|
|
902
933
|
case 'pub(rpc.send)':
|
|
@@ -919,6 +950,8 @@ export default class KoniTabs {
|
|
|
919
950
|
return this.accountsListV2(url, request);
|
|
920
951
|
case 'pub(accounts.subscribeV2)':
|
|
921
952
|
return this.accountsSubscribeV2(url, request, id, port);
|
|
953
|
+
case 'pub(accounts.unsubscribe)':
|
|
954
|
+
return this.accountsUnsubscribe(url, request);
|
|
922
955
|
case 'evm(events.subscribe)':
|
|
923
956
|
return await this.evmSubscribeEvents(url, id, port);
|
|
924
957
|
case 'evm(request)':
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.1.
|
|
20
|
+
"version": "1.1.6-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -720,11 +720,21 @@
|
|
|
720
720
|
"require": "./cjs/services/request-service/constants.js",
|
|
721
721
|
"default": "./services/request-service/constants.js"
|
|
722
722
|
},
|
|
723
|
+
"./services/request-service/handler": {
|
|
724
|
+
"types": "./services/request-service/handler/index.d.ts",
|
|
725
|
+
"require": "./cjs/services/request-service/handler/index.js",
|
|
726
|
+
"default": "./services/request-service/handler/index.js"
|
|
727
|
+
},
|
|
723
728
|
"./services/request-service/handler/AuthRequestHandler": {
|
|
724
729
|
"types": "./services/request-service/handler/AuthRequestHandler.d.ts",
|
|
725
730
|
"require": "./cjs/services/request-service/handler/AuthRequestHandler.js",
|
|
726
731
|
"default": "./services/request-service/handler/AuthRequestHandler.js"
|
|
727
732
|
},
|
|
733
|
+
"./services/request-service/handler/ConnectWCRequestHandler": {
|
|
734
|
+
"types": "./services/request-service/handler/ConnectWCRequestHandler.d.ts",
|
|
735
|
+
"require": "./cjs/services/request-service/handler/ConnectWCRequestHandler.js",
|
|
736
|
+
"default": "./services/request-service/handler/ConnectWCRequestHandler.js"
|
|
737
|
+
},
|
|
728
738
|
"./services/request-service/handler/EvmRequestHandler": {
|
|
729
739
|
"types": "./services/request-service/handler/EvmRequestHandler.d.ts",
|
|
730
740
|
"require": "./cjs/services/request-service/handler/EvmRequestHandler.js",
|
|
@@ -735,6 +745,11 @@
|
|
|
735
745
|
"require": "./cjs/services/request-service/handler/MetadataRequestHandler.js",
|
|
736
746
|
"default": "./services/request-service/handler/MetadataRequestHandler.js"
|
|
737
747
|
},
|
|
748
|
+
"./services/request-service/handler/NotSupportWCRequestHandler": {
|
|
749
|
+
"types": "./services/request-service/handler/NotSupportWCRequestHandler.d.ts",
|
|
750
|
+
"require": "./cjs/services/request-service/handler/NotSupportWCRequestHandler.js",
|
|
751
|
+
"default": "./services/request-service/handler/NotSupportWCRequestHandler.js"
|
|
752
|
+
},
|
|
738
753
|
"./services/request-service/handler/PopupHandler": {
|
|
739
754
|
"types": "./services/request-service/handler/PopupHandler.d.ts",
|
|
740
755
|
"require": "./cjs/services/request-service/handler/PopupHandler.js",
|
|
@@ -745,11 +760,6 @@
|
|
|
745
760
|
"require": "./cjs/services/request-service/handler/SubstrateRequestHandler.js",
|
|
746
761
|
"default": "./services/request-service/handler/SubstrateRequestHandler.js"
|
|
747
762
|
},
|
|
748
|
-
"./services/request-service/handler/WalletConnectRequestHandler": {
|
|
749
|
-
"types": "./services/request-service/handler/WalletConnectRequestHandler.d.ts",
|
|
750
|
-
"require": "./cjs/services/request-service/handler/WalletConnectRequestHandler.js",
|
|
751
|
-
"default": "./services/request-service/handler/WalletConnectRequestHandler.js"
|
|
752
|
-
},
|
|
753
763
|
"./services/request-service/helper": {
|
|
754
764
|
"types": "./services/request-service/helper/index.d.ts",
|
|
755
765
|
"require": "./cjs/services/request-service/helper/index.js",
|
|
@@ -1173,11 +1183,11 @@
|
|
|
1173
1183
|
"@reduxjs/toolkit": "^1.9.1",
|
|
1174
1184
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
1175
1185
|
"@substrate/connect": "^0.7.26",
|
|
1176
|
-
"@subwallet/chain-list": "^0.2.
|
|
1177
|
-
"@subwallet/extension-base": "^1.1.
|
|
1178
|
-
"@subwallet/extension-chains": "^1.1.
|
|
1179
|
-
"@subwallet/extension-dapp": "^1.1.
|
|
1180
|
-
"@subwallet/extension-inject": "^1.1.
|
|
1186
|
+
"@subwallet/chain-list": "^0.2.8",
|
|
1187
|
+
"@subwallet/extension-base": "^1.1.6-0",
|
|
1188
|
+
"@subwallet/extension-chains": "^1.1.6-0",
|
|
1189
|
+
"@subwallet/extension-dapp": "^1.1.6-0",
|
|
1190
|
+
"@subwallet/extension-inject": "^1.1.6-0",
|
|
1181
1191
|
"@subwallet/keyring": "^0.0.10",
|
|
1182
1192
|
"@subwallet/ui-keyring": "^0.0.10",
|
|
1183
1193
|
"@walletconnect/sign-client": "^2.8.4",
|
|
@@ -1202,7 +1212,7 @@
|
|
|
1202
1212
|
"json-rpc-engine": "^6.1.0",
|
|
1203
1213
|
"manta-extension-sdk": "^1.1.0",
|
|
1204
1214
|
"moment": "^2.29.4",
|
|
1205
|
-
"protobufjs": "^7.
|
|
1215
|
+
"protobufjs": "^7.2.4",
|
|
1206
1216
|
"rxjs": "^7.8.1",
|
|
1207
1217
|
"web3": "^1.10.0",
|
|
1208
1218
|
"web3-core": "^1.10.0",
|
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.1.
|
|
10
|
+
version: '1.1.6-0'
|
|
11
11
|
};
|
package/page/Accounts.js
CHANGED
|
@@ -14,11 +14,16 @@ export default class Accounts {
|
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
subscribe(cb) {
|
|
17
|
+
let id = null;
|
|
17
18
|
sendRequest('pub(accounts.subscribeV2)', {
|
|
18
19
|
accountAuthType: 'substrate'
|
|
19
|
-
}, cb).
|
|
20
|
+
}, cb).then(subId => {
|
|
21
|
+
id = subId;
|
|
22
|
+
}).catch(console.error);
|
|
20
23
|
return () => {
|
|
21
|
-
|
|
24
|
+
id && sendRequest('pub(accounts.unsubscribe)', {
|
|
25
|
+
id
|
|
26
|
+
}).catch(console.error);
|
|
22
27
|
};
|
|
23
28
|
}
|
|
24
29
|
}
|
package/page/Injected.js
CHANGED
|
@@ -11,5 +11,10 @@ export default class {
|
|
|
11
11
|
this.metadata = new Metadata(sendRequest);
|
|
12
12
|
this.provider = new PostMessageProvider(sendRequest);
|
|
13
13
|
this.signer = new Signer(sendRequest);
|
|
14
|
+
setInterval(() => {
|
|
15
|
+
sendRequest('pub(ping)', null).catch(() => {
|
|
16
|
+
console.error('Extension unavailable, ping failed');
|
|
17
|
+
});
|
|
18
|
+
}, 5000 + Math.floor(Math.random() * 5000));
|
|
14
19
|
}
|
|
15
20
|
}
|
|
@@ -5,7 +5,7 @@ import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
|
5
5
|
import { KeyringService } from '@subwallet/extension-base/services/keyring-service';
|
|
6
6
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
7
7
|
import { AuthUrls } from '@subwallet/extension-base/services/request-service/types';
|
|
8
|
-
import { BehaviorSubject
|
|
8
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
9
|
export default class AuthRequestHandler {
|
|
10
10
|
#private;
|
|
11
11
|
private keyringService;
|
|
@@ -31,8 +31,8 @@ export default class AuthRequestHandler {
|
|
|
31
31
|
private authCompleteV2;
|
|
32
32
|
authorizeUrlV2(url: string, request: RequestAuthorizeTab): Promise<boolean>;
|
|
33
33
|
getAuthRequestV2(id: string): AuthRequestV2;
|
|
34
|
-
get subscribeEvmChainChange():
|
|
35
|
-
get subscribeAuthorizeUrlSubject():
|
|
34
|
+
get subscribeEvmChainChange(): BehaviorSubject<AuthUrls>;
|
|
35
|
+
get subscribeAuthorizeUrlSubject(): BehaviorSubject<AuthUrls>;
|
|
36
36
|
ensureUrlAuthorizedV2(url: string): Promise<boolean>;
|
|
37
37
|
resetWallet(): void;
|
|
38
38
|
}
|