@subwallet/extension-base 1.1.4-0 → 1.1.5-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.
Files changed (40) hide show
  1. package/background/KoniTypes.d.ts +14 -4
  2. package/background/types.d.ts +4 -0
  3. package/cjs/koni/api/nft/config.js +12 -9
  4. package/cjs/koni/background/handlers/Extension.js +49 -11
  5. package/cjs/koni/background/handlers/Tabs.js +65 -31
  6. package/cjs/packageInfo.js +1 -1
  7. package/cjs/page/Accounts.js +7 -2
  8. package/cjs/page/Injected.js +5 -0
  9. package/cjs/services/request-service/handler/AuthRequestHandler.js +4 -2
  10. package/cjs/services/request-service/handler/{WalletConnectRequestHandler.js → ConnectWCRequestHandler.js} +9 -9
  11. package/cjs/services/request-service/handler/NotSupportWCRequestHandler.js +71 -0
  12. package/cjs/services/request-service/handler/index.js +55 -0
  13. package/cjs/services/request-service/index.js +36 -22
  14. package/cjs/services/transaction-service/index.js +5 -1
  15. package/cjs/services/wallet-connect-service/helpers.js +10 -1
  16. package/cjs/services/wallet-connect-service/index.js +5 -0
  17. package/koni/api/nft/config.js +12 -9
  18. package/koni/background/handlers/Extension.d.ts +4 -1
  19. package/koni/background/handlers/Extension.js +43 -7
  20. package/koni/background/handlers/Tabs.d.ts +3 -1
  21. package/koni/background/handlers/Tabs.js +44 -11
  22. package/package.json +21 -11
  23. package/packageInfo.js +1 -1
  24. package/page/Accounts.js +7 -2
  25. package/page/Injected.js +5 -0
  26. package/services/request-service/handler/AuthRequestHandler.d.ts +3 -3
  27. package/services/request-service/handler/AuthRequestHandler.js +5 -3
  28. package/services/request-service/handler/{WalletConnectRequestHandler.d.ts → ConnectWCRequestHandler.d.ts} +1 -1
  29. package/services/request-service/handler/{WalletConnectRequestHandler.js → ConnectWCRequestHandler.js} +8 -8
  30. package/services/request-service/handler/NotSupportWCRequestHandler.d.ts +15 -0
  31. package/services/request-service/handler/NotSupportWCRequestHandler.js +62 -0
  32. package/services/request-service/handler/index.d.ts +7 -0
  33. package/services/request-service/handler/index.js +10 -0
  34. package/services/request-service/index.d.ts +11 -6
  35. package/services/request-service/index.js +31 -16
  36. package/services/transaction-service/index.js +5 -1
  37. package/services/wallet-connect-service/helpers.d.ts +2 -1
  38. package/services/wallet-connect-service/helpers.js +8 -0
  39. package/services/wallet-connect-service/index.js +6 -1
  40. package/services/wallet-connect-service/types.d.ts +5 -0
@@ -2,11 +2,11 @@
2
2
  import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
3
3
  import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
4
4
  import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
5
- import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
5
+ import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountSubscribe, RequestAccountUnsubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
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
+ import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
10
10
  import { InjectedAccount, MetadataDefBase } from '@subwallet/extension-inject/types';
11
11
  import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
12
12
  import { KeyringOptions } from '@subwallet/ui-keyring/options/types';
@@ -1466,6 +1466,12 @@ export interface RequestReconnectConnectWalletSession {
1466
1466
  export interface RequestDisconnectWalletConnectSession {
1467
1467
  topic: string;
1468
1468
  }
1469
+ export interface RequestRejectWalletConnectNotSupport {
1470
+ id: string;
1471
+ }
1472
+ export interface RequestApproveWalletConnectNotSupport {
1473
+ id: string;
1474
+ }
1469
1475
  export interface MantaPayConfig {
1470
1476
  address: string;
1471
1477
  zkAddress: string;
@@ -1626,7 +1632,8 @@ export interface KoniRequestSignatures {
1626
1632
  'pri(confirmations.complete)': [RequestConfirmationComplete, boolean];
1627
1633
  'pub(utils.getRandom)': [RandomTestRequest, number];
1628
1634
  'pub(accounts.listV2)': [RequestAccountList, InjectedAccount[]];
1629
- 'pub(accounts.subscribeV2)': [RequestAccountSubscribe, boolean, InjectedAccount[]];
1635
+ 'pub(accounts.subscribeV2)': [RequestAccountSubscribe, string, InjectedAccount[]];
1636
+ 'pub(accounts.unsubscribe)': [RequestAccountUnsubscribe, boolean];
1630
1637
  'pri(account.isLocked)': [RequestAccountIsLocked, ResponseAccountIsLocked];
1631
1638
  'pri(qr.transaction.parse.substrate)': [RequestParseTransactionSubstrate, ResponseParseTransactionSubstrate];
1632
1639
  'pri(qr.transaction.parse.evm)': [RequestQrParseRLP, ResponseQrParseRLP];
@@ -1669,12 +1676,15 @@ export interface KoniRequestSignatures {
1669
1676
  'mobile(subscription.restart)': [SubscriptionServiceType[], void];
1670
1677
  'pub(token.add)': [RequestAddPspToken, boolean];
1671
1678
  'pri(walletConnect.connect)': [RequestConnectWalletConnect, boolean];
1672
- 'pri(walletConnect.requests.subscribe)': [null, WalletConnectSessionRequest[], WalletConnectSessionRequest[]];
1679
+ 'pri(walletConnect.requests.connect.subscribe)': [null, WalletConnectSessionRequest[], WalletConnectSessionRequest[]];
1673
1680
  'pri(walletConnect.session.approve)': [RequestApproveConnectWalletSession, boolean];
1674
1681
  'pri(walletConnect.session.reject)': [RequestRejectConnectWalletSession, boolean];
1675
1682
  'pri(walletConnect.session.reconnect)': [RequestReconnectConnectWalletSession, boolean];
1676
1683
  'pri(walletConnect.session.subscribe)': [null, SessionTypes.Struct[], SessionTypes.Struct[]];
1677
1684
  'pri(walletConnect.session.disconnect)': [RequestDisconnectWalletConnectSession, boolean];
1685
+ 'pri(walletConnect.requests.notSupport.subscribe)': [null, WalletConnectNotSupportRequest[], WalletConnectNotSupportRequest[]];
1686
+ 'pri(walletConnect.notSupport.approve)': [RequestApproveWalletConnectNotSupport, boolean];
1687
+ 'pri(walletConnect.notSupport.reject)': [RequestRejectWalletConnectNotSupport, boolean];
1678
1688
  'pri(metadata.find)': [RequestFindRawMetadata, ResponseFindRawMetadata];
1679
1689
  }
1680
1690
  export interface ApplicationMetadataType {
@@ -134,6 +134,7 @@ export interface RequestSignatures extends KoniRequestSignatures {
134
134
  'pub(metadata.list)': [null, InjectedMetadataKnown[]];
135
135
  'pub(metadata.provide)': [MetadataDef, boolean];
136
136
  'pub(phishing.redirectIfDenied)': [null, boolean];
137
+ 'pub(ping)': [null, boolean];
137
138
  'pub(rpc.listProviders)': [void, ResponseRpcListProviders];
138
139
  'pub(rpc.send)': [RequestRpcSend, JsonRpcResponse<unknown>];
139
140
  'pub(rpc.startProvider)': [string, ProviderMeta];
@@ -252,6 +253,9 @@ export interface RequestAccountList {
252
253
  export interface RequestAccountSubscribe {
253
254
  accountAuthType?: AccountAuthType;
254
255
  }
256
+ export interface RequestAccountUnsubscribe {
257
+ id: string;
258
+ }
255
259
  export interface RequestRpcSend {
256
260
  method: string;
257
261
  params: unknown[];
@@ -103,9 +103,6 @@ exports.SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = SUPPORTED_TRANSFER_SUBSTRATE_C
103
103
  SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME["pioneer"] = "pioneer";
104
104
  })(SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME || (exports.SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME = {}));
105
105
  const RANDOM_IPFS_GATEWAY_SETTING = [{
106
- provider: IPFS_W3S_LINK,
107
- weight: 1
108
- }, {
109
106
  provider: CF_IPFS_GATEWAY,
110
107
  weight: 4
111
108
  }, {
@@ -120,12 +117,6 @@ const RANDOM_IPFS_GATEWAY_SETTING = [{
120
117
  }, {
121
118
  provider: DWEB_LINK,
122
119
  weight: 5
123
- }, {
124
- provider: IPFS_GATEWAY_4EVERLAND,
125
- weight: 2
126
- }, {
127
- provider: IPFS_HARDBIN,
128
- weight: 1
129
120
  }];
130
121
  if (!_utils.RuntimeInfo.protocol || _utils.RuntimeInfo.protocol && !_utils.RuntimeInfo.protocol.startsWith('http')) {
131
122
  RANDOM_IPFS_GATEWAY_SETTING.push({
@@ -136,6 +127,18 @@ if (!_utils.RuntimeInfo.protocol || _utils.RuntimeInfo.protocol && !_utils.Runti
136
127
  provider: IPFS_FLEEK,
137
128
  weight: 4
138
129
  });
130
+ RANDOM_IPFS_GATEWAY_SETTING.push({
131
+ provider: IPFS_HARDBIN,
132
+ weight: 1
133
+ });
134
+ RANDOM_IPFS_GATEWAY_SETTING.push({
135
+ provider: IPFS_GATEWAY_4EVERLAND,
136
+ weight: 2
137
+ });
138
+ RANDOM_IPFS_GATEWAY_SETTING.push({
139
+ provider: IPFS_W3S_LINK,
140
+ weight: 1
141
+ });
139
142
  }
140
143
  const RANDOM_IPFS_GATEWAY_TOTAL_WEIGHT = RANDOM_IPFS_GATEWAY_SETTING.reduce((value, item) => value + item.weight, 0);
141
144
  function getRandomIpfsGateway() {
@@ -696,10 +696,10 @@ class KoniExtension {
696
696
  });
697
697
  return true;
698
698
  }
699
- getNonReadonlyAccounts() {
699
+ getAccounts() {
700
700
  const storedAccounts = this.#koniState.keyringService.accounts;
701
701
  const transformedAccounts = transformAccounts(storedAccounts);
702
- return transformedAccounts.filter(a => !a.isReadOnly).map(a => a.address);
702
+ return transformedAccounts.map(a => a.address);
703
703
  }
704
704
  isAddressValidWithAuthType(address, accountAuthType) {
705
705
  if (accountAuthType === 'substrate') {
@@ -721,12 +721,12 @@ class KoniExtension {
721
721
  _changeAuthorizationAll(connectValue, callBack) {
722
722
  this.#koniState.getAuthorize(value => {
723
723
  (0, _util.assert)(value, 'The source is not known');
724
- const nonReadonlyAccounts = this.getNonReadonlyAccounts();
724
+ const accounts = this.getAccounts();
725
725
  Object.keys(value).forEach(url => {
726
726
  if (!value[url].isAllowed) {
727
727
  return;
728
728
  }
729
- const targetAccounts = this.filterAccountsByAccountAuthType(nonReadonlyAccounts, value[url].accountAuthType);
729
+ const targetAccounts = this.filterAccountsByAccountAuthType(accounts, value[url].accountAuthType);
730
730
  targetAccounts.forEach(address => {
731
731
  value[url].isAllowedMap[address] = connectValue;
732
732
  });
@@ -749,8 +749,8 @@ class KoniExtension {
749
749
  _changeAuthorization(url, connectValue, callBack) {
750
750
  this.#koniState.getAuthorize(value => {
751
751
  (0, _util.assert)(value[url], 'The source is not known');
752
- const nonReadonlyAccounts = this.getNonReadonlyAccounts();
753
- const targetAccounts = this.filterAccountsByAccountAuthType(nonReadonlyAccounts, value[url].accountAuthType);
752
+ const accounts = this.getAccounts();
753
+ const targetAccounts = this.filterAccountsByAccountAuthType(accounts, value[url].accountAuthType);
754
754
  targetAccounts.forEach(address => {
755
755
  value[url].isAllowedMap[address] = connectValue;
756
756
  });
@@ -3314,11 +3314,39 @@ class KoniExtension {
3314
3314
  await this.#koniState.walletConnectService.disconnect(topic);
3315
3315
  return true;
3316
3316
  }
3317
- async enableMantaPay(_ref86) {
3317
+ WCNotSupportSubscribe(id, port) {
3318
+ const cb = (0, _subscriptions.createSubscription)(id, port);
3319
+ const subscription = this.#koniState.requestService.notSupportWCSubject.subscribe(requests => cb(requests));
3320
+ port.onDisconnect.addListener(() => {
3321
+ this.cancelSubscription(id);
3322
+ subscription.unsubscribe();
3323
+ });
3324
+ return this.#koniState.requestService.allNotSupportWCRequests;
3325
+ }
3326
+ approveWalletConnectNotSupport(_ref86) {
3327
+ let {
3328
+ id
3329
+ } = _ref86;
3330
+ const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3331
+ request.resolve();
3332
+ return true;
3333
+ }
3334
+ rejectWalletConnectNotSupport(_ref87) {
3335
+ let {
3336
+ id
3337
+ } = _ref87;
3338
+ const request = this.#koniState.requestService.getNotSupportWCRequest(id);
3339
+ request.reject(new Error('USER_REJECTED'));
3340
+ return true;
3341
+ }
3342
+
3343
+ /// Manta
3344
+
3345
+ async enableMantaPay(_ref88) {
3318
3346
  let {
3319
3347
  address,
3320
3348
  password
3321
- } = _ref86;
3349
+ } = _ref88;
3322
3350
  // always takes the current account
3323
3351
  function timeout() {
3324
3352
  return new Promise(resolve => setTimeout(resolve, 1500));
@@ -3442,10 +3470,10 @@ class KoniExtension {
3442
3470
 
3443
3471
  /// Metadata
3444
3472
 
3445
- async findRawMetadata(_ref87) {
3473
+ async findRawMetadata(_ref89) {
3446
3474
  let {
3447
3475
  genesisHash
3448
- } = _ref87;
3476
+ } = _ref89;
3449
3477
  const {
3450
3478
  metadata,
3451
3479
  specVersion
@@ -3840,7 +3868,7 @@ class KoniExtension {
3840
3868
  /// Wallet Connect
3841
3869
  case 'pri(walletConnect.connect)':
3842
3870
  return this.connectWalletConnect(request);
3843
- case 'pri(walletConnect.requests.subscribe)':
3871
+ case 'pri(walletConnect.requests.connect.subscribe)':
3844
3872
  return this.connectWCSubscribe(id, port);
3845
3873
  case 'pri(walletConnect.session.approve)':
3846
3874
  return this.approveWalletConnectSession(request);
@@ -3850,6 +3878,16 @@ class KoniExtension {
3850
3878
  return this.subscribeWalletConnectSessions(id, port);
3851
3879
  case 'pri(walletConnect.session.disconnect)':
3852
3880
  return this.disconnectWalletConnectSession(request);
3881
+
3882
+ // Not support
3883
+ case 'pri(walletConnect.requests.notSupport.subscribe)':
3884
+ return this.WCNotSupportSubscribe(id, port);
3885
+ case 'pri(walletConnect.notSupport.approve)':
3886
+ return this.approveWalletConnectNotSupport(request);
3887
+ case 'pri(walletConnect.notSupport.reject)':
3888
+ return this.rejectWalletConnectNotSupport(request);
3889
+
3890
+ // Manta
3853
3891
  case 'pri(mantaPay.enable)':
3854
3892
  return await this.enableMantaPay(request);
3855
3893
  case 'pri(mantaPay.initSyncMantaPay)':
@@ -109,6 +109,7 @@ const chainPatrolCheckUrl = async url => {
109
109
  };
110
110
  exports.chainPatrolCheckUrl = chainPatrolCheckUrl;
111
111
  class KoniTabs {
112
+ #accountSubs = {};
112
113
  #koniState;
113
114
  evmEventEmitterMap = {};
114
115
  #chainPatrolService = _constants2.DEFAULT_CHAIN_PATROL_ENABLE;
@@ -137,17 +138,25 @@ class KoniTabs {
137
138
  (0, _util.assert)(pair, 'Unable to find keypair');
138
139
  return pair;
139
140
  }
140
- bytesSign(url, request) {
141
+ async bytesSign(url, request) {
141
142
  const address = request.address;
142
143
  const pair = this.getSigningPair(address);
144
+ const authInfo = await this.getAuthInfo(url);
145
+ if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[pair.address]) {
146
+ throw new Error('Account {{address}} not in allowed list'.replace('{{address}}', address));
147
+ }
143
148
  return this.#koniState.sign(url, new _RequestBytesSign.default(request), {
144
149
  address,
145
150
  ...pair.meta
146
151
  });
147
152
  }
148
- extrinsicSign(url, request) {
153
+ async extrinsicSign(url, request) {
149
154
  const address = request.address;
150
155
  const pair = this.getSigningPair(address);
156
+ const authInfo = await this.getAuthInfo(url);
157
+ if (!authInfo || !authInfo.isAllowed || !authInfo.isAllowedMap[pair.address]) {
158
+ throw new Error('Account {{address}} not in allowed list'.replace('{{address}}', address));
159
+ }
151
160
  return this.#koniState.sign(url, new _RequestExtrinsicSign.default(request), {
152
161
  address,
153
162
  ...pair.meta
@@ -255,8 +264,8 @@ class KoniTabs {
255
264
  createUnsubscriptionHandle(id, unsubscribe) {
256
265
  this.#koniState.createUnsubscriptionHandle(id, unsubscribe);
257
266
  }
258
- async getAuthInfo(url) {
259
- const authList = await this.#koniState.getAuthList();
267
+ async getAuthInfo(url, fromList) {
268
+ const authList = fromList || (await this.#koniState.getAuthList());
260
269
  const shortenUrl = (0, _utils2.stripUrl)(url);
261
270
  return authList[shortenUrl];
262
271
  }
@@ -273,15 +282,36 @@ class KoniTabs {
273
282
  accountAuthType
274
283
  } = _ref11;
275
284
  const cb = (0, _subscriptions.createSubscription)(id, port);
276
- const subscription = this.#koniState.keyringService.accountSubject.subscribe(accounts => {
277
- this.getAuthInfo(url).then(authInfo => {
278
- cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
279
- }).catch(console.error);
280
- });
281
- this.createUnsubscriptionHandle(id, subscription.unsubscribe);
285
+ const authInfoSubject = this.#koniState.requestService.subscribeAuthorizeUrlSubject;
286
+
287
+ // Update unsubscribe from @polkadot/extension-base
288
+ this.#accountSubs[id] = {
289
+ subscription: authInfoSubject.subscribe(infos => {
290
+ this.getAuthInfo(url, infos).then(authInfo => {
291
+ const accounts = this.#koniState.keyringService.accounts;
292
+ return cb(transformAccountsV2(accounts, false, authInfo, accountAuthType));
293
+ }).catch(console.error);
294
+ }),
295
+ url
296
+ };
282
297
  port.onDisconnect.addListener(() => {
283
- this.cancelSubscription(id);
298
+ this.accountsUnsubscribe(url, {
299
+ id
300
+ });
284
301
  });
302
+ return id;
303
+ }
304
+ accountsUnsubscribe(url, _ref12) {
305
+ let {
306
+ id
307
+ } = _ref12;
308
+ const sub = this.#accountSubs[id];
309
+ if (!sub || sub.url !== url) {
310
+ return false;
311
+ }
312
+ delete this.#accountSubs[id];
313
+ (0, _subscriptions.unsubscribe)(id);
314
+ sub.subscription.unsubscribe();
285
315
  return true;
286
316
  }
287
317
  authorizeV2(url, request) {
@@ -382,10 +412,10 @@ class KoniTabs {
382
412
  date: new Date().getTime()
383
413
  }];
384
414
  }
385
- async switchEvmChain(id, url, _ref12) {
415
+ async switchEvmChain(id, url, _ref13) {
386
416
  let {
387
417
  params
388
- } = _ref12;
418
+ } = _ref13;
389
419
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
390
420
  const chainId = params[0].chainId;
391
421
  const evmState = await this.getEvmState(url);
@@ -400,11 +430,11 @@ class KoniTabs {
400
430
  }
401
431
  return null;
402
432
  }
403
- async addEvmToken(id, url, _ref13) {
433
+ async addEvmToken(id, url, _ref14) {
404
434
  var _input$type, _input$options, _input$options2, _input$options3, _input$options4, _input$options5;
405
435
  let {
406
436
  params
407
- } = _ref13;
437
+ } = _ref14;
408
438
  const input = params;
409
439
  const _tokenType = (input === null || input === void 0 ? void 0 : (_input$type = input.type) === null || _input$type === void 0 ? void 0 : _input$type.toLowerCase()) || '';
410
440
  if (_tokenType !== 'erc20' && _tokenType !== 'erc721') {
@@ -457,10 +487,10 @@ class KoniTabs {
457
487
 
458
488
  return await this.#koniState.addTokenConfirm(id, url, tokenInfo);
459
489
  }
460
- async addEvmChain(id, url, _ref14) {
490
+ async addEvmChain(id, url, _ref15) {
461
491
  let {
462
492
  params
463
- } = _ref14;
493
+ } = _ref15;
464
494
  const input = params;
465
495
  if (input && input.length > 0) {
466
496
  const {
@@ -663,11 +693,11 @@ class KoniTabs {
663
693
  const networkCheckInterval = setInterval(networkCheck, _constants.CRON_GET_API_MAP_STATUS);
664
694
  const provider = await this.getEvmProvider(url);
665
695
  const eventMap = {};
666
- eventMap.data = _ref15 => {
696
+ eventMap.data = _ref16 => {
667
697
  let {
668
698
  method,
669
699
  params
670
- } = _ref15;
700
+ } = _ref16;
671
701
  emitEvent('message', {
672
702
  type: method,
673
703
  data: params
@@ -676,8 +706,8 @@ class KoniTabs {
676
706
  eventMap.error = rs => {
677
707
  emitEvent('error', rs);
678
708
  };
679
- Object.entries(eventMap).forEach(_ref16 => {
680
- let [event, callback] = _ref16;
709
+ Object.entries(eventMap).forEach(_ref17 => {
710
+ let [event, callback] = _ref17;
681
711
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
682
712
  (provider === null || provider === void 0 ? void 0 : provider.on) && (provider === null || provider === void 0 ? void 0 : provider.on(event, callback));
683
713
  });
@@ -691,8 +721,8 @@ class KoniTabs {
691
721
  if (this.evmEventEmitterMap[url][id]) {
692
722
  delete this.evmEventEmitterMap[url][id];
693
723
  }
694
- Object.entries(eventMap).forEach(_ref17 => {
695
- let [event, callback] = _ref17;
724
+ Object.entries(eventMap).forEach(_ref18 => {
725
+ let [event, callback] = _ref18;
696
726
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
697
727
  (provider === null || provider === void 0 ? void 0 : provider.removeListener) && (provider === null || provider === void 0 ? void 0 : provider.removeListener(event, callback));
698
728
  });
@@ -727,11 +757,11 @@ class KoniTabs {
727
757
  }
728
758
  return provider;
729
759
  }
730
- async performWeb3Method(id, url, _ref18, callback) {
760
+ async performWeb3Method(id, url, _ref19, callback) {
731
761
  let {
732
762
  method,
733
763
  params
734
- } = _ref18;
764
+ } = _ref19;
735
765
  const provider = await this.getEvmProvider(url);
736
766
  this.checkAndHandleProviderStatus(provider);
737
767
  return new Promise((resolve, reject) => {
@@ -756,11 +786,11 @@ class KoniTabs {
756
786
  const allowedAccounts = await this.getEvmCurrentAccount(url, true);
757
787
  return !!allowedAccounts.find(acc => acc.toLowerCase() === address.toLowerCase());
758
788
  }
759
- async evmSign(id, url, _ref19) {
789
+ async evmSign(id, url, _ref20) {
760
790
  let {
761
791
  method,
762
792
  params
763
- } = _ref19;
793
+ } = _ref20;
764
794
  const allowedAccounts = await this.getEvmCurrentAccount(url, true);
765
795
  const signResult = await this.#koniState.evmSign(id, url, method, params, allowedAccounts);
766
796
  if (signResult) {
@@ -769,10 +799,10 @@ class KoniTabs {
769
799
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, 'Have something wrong to sign message');
770
800
  }
771
801
  }
772
- async evmSendTransaction(id, url, _ref20) {
802
+ async evmSendTransaction(id, url, _ref21) {
773
803
  let {
774
804
  params
775
- } = _ref20;
805
+ } = _ref21;
776
806
  const transactionParams = params[0];
777
807
  const canUseAccount = transactionParams.from && this.canUseAccount(transactionParams.from, url);
778
808
  const evmState = await this.getEvmState(url);
@@ -870,11 +900,11 @@ class KoniTabs {
870
900
  return false;
871
901
  }
872
902
  }
873
- async addPspToken(id, url, _ref21) {
903
+ async addPspToken(id, url, _ref22) {
874
904
  let {
875
905
  genesisHash,
876
906
  tokenInfo: input
877
- } = _ref21;
907
+ } = _ref22;
878
908
  const _tokenType = input.type;
879
909
  if (_tokenType !== 'psp22' && _tokenType !== 'psp34') {
880
910
  throw new _EvmProviderError.EvmProviderError(_KoniTypes.EvmProviderErrorType.INVALID_PARAMS, `Assets type ${_tokenType} is not supported`);
@@ -948,6 +978,8 @@ class KoniTabs {
948
978
  return this.metadataList(url);
949
979
  case 'pub(metadata.provide)':
950
980
  return this.metadataProvide(url, request);
981
+ case 'pub(ping)':
982
+ return Promise.resolve(true);
951
983
  case 'pub(rpc.listProviders)':
952
984
  return this.rpcListProviders();
953
985
  case 'pub(rpc.send)':
@@ -970,6 +1002,8 @@ class KoniTabs {
970
1002
  return this.accountsListV2(url, request);
971
1003
  case 'pub(accounts.subscribeV2)':
972
1004
  return this.accountsSubscribeV2(url, request, id, port);
1005
+ case 'pub(accounts.unsubscribe)':
1006
+ return this.accountsUnsubscribe(url, request);
973
1007
  case 'evm(events.subscribe)':
974
1008
  return await this.evmSubscribeEvents(url, id, port);
975
1009
  case 'evm(request)':
@@ -13,6 +13,6 @@ const packageInfo = {
13
13
  name: '@subwallet/extension-base',
14
14
  path: typeof __dirname === 'string' ? __dirname : 'auto',
15
15
  type: 'cjs',
16
- version: '1.1.4-0'
16
+ version: '1.1.5-0'
17
17
  };
18
18
  exports.packageInfo = packageInfo;
@@ -20,11 +20,16 @@ class Accounts {
20
20
  });
21
21
  }
22
22
  subscribe(cb) {
23
+ let id = null;
23
24
  sendRequest('pub(accounts.subscribeV2)', {
24
25
  accountAuthType: 'substrate'
25
- }, cb).catch(error => console.error(error));
26
+ }, cb).then(subId => {
27
+ id = subId;
28
+ }).catch(console.error);
26
29
  return () => {
27
- // FIXME we need the ability to unsubscribe
30
+ id && sendRequest('pub(accounts.unsubscribe)', {
31
+ id
32
+ }).catch(console.error);
28
33
  };
29
34
  }
30
35
  }
@@ -18,6 +18,11 @@ class _default {
18
18
  this.metadata = new _Metadata.default(sendRequest);
19
19
  this.provider = new _PostMessageProvider.default(sendRequest);
20
20
  this.signer = new _Signer.default(sendRequest);
21
+ setInterval(() => {
22
+ sendRequest('pub(ping)', null).catch(() => {
23
+ console.error('Extension unavailable, ping failed');
24
+ });
25
+ }, 5000 + Math.floor(Math.random() * 5000));
21
26
  }
22
27
  }
23
28
  exports.default = _default;
@@ -23,8 +23,8 @@ class AuthRequestHandler {
23
23
  authorizeStore = new _Authorize.default();
24
24
  #authRequestsV2 = {};
25
25
  authorizeCached = undefined;
26
- authorizeUrlSubject = new _rxjs.Subject();
27
- evmChainSubject = new _rxjs.Subject();
26
+ authorizeUrlSubject = new _rxjs.BehaviorSubject({});
27
+ evmChainSubject = new _rxjs.BehaviorSubject({});
28
28
  authSubjectV2 = new _rxjs.BehaviorSubject([]);
29
29
  constructor(requestService, chainService, keyringService) {
30
30
  this.keyringService = keyringService;
@@ -75,6 +75,8 @@ class AuthRequestHandler {
75
75
  } else {
76
76
  this.authorizeStore.get('authUrls', data => {
77
77
  this.authorizeCached = data || {};
78
+ this.evmChainSubject.next(this.authorizeCached);
79
+ this.authorizeUrlSubject.next(this.authorizeCached);
78
80
  update(this.authorizeCached);
79
81
  });
80
82
  }
@@ -9,15 +9,15 @@ var _rxjs = require("rxjs");
9
9
  // SPDX-License-Identifier: Apache-2.0
10
10
 
11
11
  // WC = WalletConnect
12
- class WalletConnectRequestHandler {
12
+ class ConnectWCRequestHandler {
13
13
  #requestService;
14
- #walletConnectSessionRequests = {};
14
+ #connectWCRequests = {};
15
15
  connectWCSubject = new _rxjs.BehaviorSubject([]);
16
16
  constructor(requestService) {
17
17
  this.#requestService = requestService;
18
18
  }
19
19
  get allConnectWCRequests() {
20
- return Object.values(this.#walletConnectSessionRequests)
20
+ return Object.values(this.#connectWCRequests)
21
21
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
22
  .map(_ref => {
23
23
  let {
@@ -29,10 +29,10 @@ class WalletConnectRequestHandler {
29
29
  });
30
30
  }
31
31
  get numConnectWCRequests() {
32
- return Object.keys(this.#walletConnectSessionRequests).length;
32
+ return Object.keys(this.#connectWCRequests).length;
33
33
  }
34
34
  getConnectWCRequest(id) {
35
- return this.#walletConnectSessionRequests[id];
35
+ return this.#connectWCRequests[id];
36
36
  }
37
37
  updateIconConnectWC(shouldClose) {
38
38
  this.connectWCSubject.next(this.allConnectWCRequests);
@@ -40,7 +40,7 @@ class WalletConnectRequestHandler {
40
40
  }
41
41
  connectWCComplete = id => {
42
42
  const complete = shouldClose => {
43
- delete this.#walletConnectSessionRequests[id];
43
+ delete this.#connectWCRequests[id];
44
44
  this.updateIconConnectWC(shouldClose);
45
45
  };
46
46
  return {
@@ -54,7 +54,7 @@ class WalletConnectRequestHandler {
54
54
  };
55
55
  addConnectWCRequest(request) {
56
56
  const id = request.id;
57
- this.#walletConnectSessionRequests[id] = {
57
+ this.#connectWCRequests[id] = {
58
58
  ...this.connectWCComplete(id),
59
59
  ...request
60
60
  };
@@ -62,10 +62,10 @@ class WalletConnectRequestHandler {
62
62
  this.#requestService.popupOpen();
63
63
  }
64
64
  resetWallet() {
65
- for (const request of Object.values(this.#walletConnectSessionRequests)) {
65
+ for (const request of Object.values(this.#connectWCRequests)) {
66
66
  request.reject(new Error('Reset wallet'));
67
67
  }
68
68
  this.connectWCSubject.next([]);
69
69
  }
70
70
  }
71
- exports.default = WalletConnectRequestHandler;
71
+ exports.default = ConnectWCRequestHandler;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _rxjs = require("rxjs");
8
+ // Copyright 2019-2022 @subwallet/extension-base authors & contributors
9
+ // SPDX-License-Identifier: Apache-2.0
10
+
11
+ // WC = WalletConnect
12
+ class NotSupportWCRequestHandler {
13
+ #requestService;
14
+ #notSupportWCRequests = {};
15
+ notSupportWCSubject = new _rxjs.BehaviorSubject([]);
16
+ constructor(requestService) {
17
+ this.#requestService = requestService;
18
+ }
19
+ get allNotSupportWCRequests() {
20
+ return Object.values(this.#notSupportWCRequests)
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
+ .map(_ref => {
23
+ let {
24
+ reject,
25
+ resolve,
26
+ ...data
27
+ } = _ref;
28
+ return data;
29
+ });
30
+ }
31
+ get numNotSupportWCRequests() {
32
+ return Object.keys(this.#notSupportWCRequests).length;
33
+ }
34
+ getNotSupportWCRequest(id) {
35
+ return this.#notSupportWCRequests[id];
36
+ }
37
+ updateIconNotSupportWC(shouldClose) {
38
+ this.notSupportWCSubject.next(this.allNotSupportWCRequests);
39
+ this.#requestService.updateIconV2(shouldClose);
40
+ }
41
+ notSupportWCComplete = id => {
42
+ const complete = shouldClose => {
43
+ delete this.#notSupportWCRequests[id];
44
+ this.updateIconNotSupportWC(shouldClose);
45
+ };
46
+ return {
47
+ reject: () => {
48
+ complete(true);
49
+ },
50
+ resolve: () => {
51
+ complete(true);
52
+ }
53
+ };
54
+ };
55
+ addNotSupportWCRequest(request) {
56
+ const id = request.id;
57
+ this.#notSupportWCRequests[id] = {
58
+ ...this.notSupportWCComplete(id),
59
+ ...request
60
+ };
61
+ this.updateIconNotSupportWC();
62
+ this.#requestService.popupOpen();
63
+ }
64
+ resetWallet() {
65
+ for (const request of Object.values(this.#notSupportWCRequests)) {
66
+ request.reject(new Error('Reset wallet'));
67
+ }
68
+ this.notSupportWCSubject.next([]);
69
+ }
70
+ }
71
+ exports.default = NotSupportWCRequestHandler;