@subwallet/extension-base 1.1.68-1 → 1.2.1

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 (168) hide show
  1. package/background/KoniTypes.d.ts +3 -1
  2. package/background/handlers/State.d.ts +1 -78
  3. package/background/handlers/State.js +1 -428
  4. package/background/types.d.ts +1 -0
  5. package/cjs/background/handlers/State.js +1 -456
  6. package/cjs/constants/storage.js +3 -1
  7. package/cjs/koni/api/dotsama/crowdloan.js +1 -2
  8. package/cjs/koni/api/nft/acala_nft/index.js +1 -3
  9. package/cjs/koni/api/nft/assethub_nft/index.js +1 -3
  10. package/cjs/koni/api/nft/assethub_unique/index.js +1 -3
  11. package/cjs/koni/api/nft/bit.country/index.js +4 -6
  12. package/cjs/koni/api/nft/config.js +1 -8
  13. package/cjs/koni/api/nft/evm_nft/index.js +1 -3
  14. package/cjs/koni/api/nft/karura_nft/index.js +1 -3
  15. package/cjs/koni/api/nft/ordinal_nft/index.js +4 -3
  16. package/cjs/koni/api/nft/rmrk_nft/index.js +4 -6
  17. package/cjs/koni/api/nft/unique_network_nft/index.js +1 -3
  18. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +1 -3
  19. package/cjs/koni/api/nft/vara_nft/index.js +1 -3
  20. package/cjs/koni/api/nft/wasm_nft/index.js +10 -17
  21. package/cjs/koni/api/staking/bonding/astar.js +2 -4
  22. package/cjs/koni/api/staking/subsquidStaking.js +9 -12
  23. package/cjs/koni/api/subquery/subquery.js +1 -3
  24. package/cjs/koni/background/handlers/Extension.js +39 -15
  25. package/cjs/koni/background/handlers/Mobile.js +7 -4
  26. package/cjs/koni/background/handlers/State.js +68 -12
  27. package/cjs/koni/background/handlers/Tabs.js +4 -1
  28. package/cjs/koni/background/handlers/index.js +71 -71
  29. package/cjs/koni/background/subscription.js +7 -6
  30. package/cjs/packageInfo.js +1 -1
  31. package/cjs/services/campaign-service/helpers.js +3 -1
  32. package/cjs/services/chain-service/index.js +37 -29
  33. package/cjs/services/chain-service/utils/patch.js +1 -3
  34. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -2
  35. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -3
  36. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -3
  37. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -2
  38. package/cjs/services/earning-service/handlers/native-staking/astar.js +3 -4
  39. package/cjs/services/event-service/index.js +0 -1
  40. package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -3
  41. package/cjs/services/keyring-service/index.js +22 -0
  42. package/cjs/services/migration-service/scripts/MigrateRemoveGenesisHash.js +28 -0
  43. package/cjs/services/migration-service/scripts/index.js +3 -1
  44. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +16 -21
  45. package/cjs/services/notification-service/NotificationService.js +3 -1
  46. package/cjs/services/price-service/coingecko.js +6 -7
  47. package/cjs/services/price-service/index.js +7 -3
  48. package/cjs/services/request-service/handler/PopupHandler.js +14 -15
  49. package/cjs/services/setting-service/SettingService.js +4 -1
  50. package/cjs/services/setting-service/constants.js +1 -1
  51. package/cjs/services/setting-service/i18n/i18n.js +2 -4
  52. package/cjs/services/storage-service/DatabaseService.js +1 -1
  53. package/cjs/services/storage-service/databases/index.js +14 -1
  54. package/cjs/services/storage-service/db-stores/KeyValue.js +13 -0
  55. package/cjs/services/subscan-service/index.js +11 -3
  56. package/cjs/services/transaction-service/index.js +3 -3
  57. package/cjs/services/wallet-connect-service/constants.js +2 -2
  58. package/cjs/services/wallet-connect-service/helpers.js +1 -4
  59. package/cjs/services/wallet-connect-service/index.js +50 -33
  60. package/cjs/storage/index.js +120 -23
  61. package/cjs/types/common/index.js +16 -0
  62. package/cjs/types/common/storage.js +1 -0
  63. package/cjs/types/index.js +11 -0
  64. package/cjs/utils/environment.js +1 -1
  65. package/cjs/utils/eth/parseTransaction/index.js +8 -10
  66. package/cjs/utils/fetch.js +55 -0
  67. package/cjs/utils/fetchStaticCache.js +2 -4
  68. package/cjs/utils/fetchStaticData.js +7 -4
  69. package/cjs/utils/index.js +24 -0
  70. package/cjs/utils/reportError.js +1 -3
  71. package/constants/storage.d.ts +1 -0
  72. package/constants/storage.js +1 -0
  73. package/koni/api/dotsama/crowdloan.js +2 -3
  74. package/koni/api/nft/acala_nft/index.js +0 -1
  75. package/koni/api/nft/assethub_nft/index.js +0 -1
  76. package/koni/api/nft/assethub_unique/index.js +0 -1
  77. package/koni/api/nft/bit.country/index.js +0 -1
  78. package/koni/api/nft/config.js +1 -7
  79. package/koni/api/nft/evm_nft/index.js +0 -1
  80. package/koni/api/nft/karura_nft/index.js +0 -1
  81. package/koni/api/nft/ordinal_nft/index.d.ts +2 -0
  82. package/koni/api/nft/ordinal_nft/index.js +4 -3
  83. package/koni/api/nft/rmrk_nft/index.js +0 -1
  84. package/koni/api/nft/unique_network_nft/index.js +0 -1
  85. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  86. package/koni/api/nft/vara_nft/index.js +0 -1
  87. package/koni/api/nft/wasm_nft/index.js +4 -10
  88. package/koni/api/staking/bonding/astar.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +10 -12
  90. package/koni/api/subquery/subquery.js +0 -1
  91. package/koni/background/handlers/Extension.d.ts +4 -0
  92. package/koni/background/handlers/Extension.js +29 -8
  93. package/koni/background/handlers/Mobile.js +9 -6
  94. package/koni/background/handlers/State.d.ts +6 -1
  95. package/koni/background/handlers/State.js +68 -12
  96. package/koni/background/handlers/Tabs.js +4 -1
  97. package/koni/background/handlers/index.d.ts +13 -7
  98. package/koni/background/handlers/index.js +67 -62
  99. package/koni/background/subscription.js +2 -1
  100. package/package.json +36 -29
  101. package/packageInfo.js +1 -1
  102. package/services/campaign-service/helpers.js +3 -1
  103. package/services/chain-service/index.js +37 -30
  104. package/services/chain-service/utils/patch.js +0 -1
  105. package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
  106. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +0 -1
  107. package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -1
  108. package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -1
  109. package/services/earning-service/handlers/native-staking/astar.js +0 -1
  110. package/services/event-service/index.js +0 -1
  111. package/services/history-service/subsquid-multi-chain-history.js +0 -1
  112. package/services/keyring-service/index.d.ts +1 -0
  113. package/services/keyring-service/index.js +19 -0
  114. package/services/migration-service/scripts/MigrateRemoveGenesisHash.d.ts +4 -0
  115. package/services/migration-service/scripts/MigrateRemoveGenesisHash.js +20 -0
  116. package/services/migration-service/scripts/index.js +3 -1
  117. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +17 -21
  118. package/services/notification-service/NotificationService.js +3 -1
  119. package/services/price-service/coingecko.js +6 -6
  120. package/services/price-service/index.js +7 -3
  121. package/services/request-service/handler/PopupHandler.d.ts +1 -1
  122. package/services/request-service/handler/PopupHandler.js +14 -15
  123. package/services/setting-service/SettingService.d.ts +1 -0
  124. package/services/setting-service/SettingService.js +4 -1
  125. package/services/setting-service/constants.js +2 -2
  126. package/services/setting-service/i18n/i18n.js +2 -4
  127. package/services/storage-service/DatabaseService.js +1 -1
  128. package/services/storage-service/databases/index.d.ts +8 -0
  129. package/services/storage-service/databases/index.js +13 -1
  130. package/services/storage-service/db-stores/KeyValue.d.ts +4 -0
  131. package/services/storage-service/db-stores/KeyValue.js +5 -0
  132. package/services/subscan-service/index.d.ts +2 -0
  133. package/services/subscan-service/index.js +10 -1
  134. package/services/transaction-service/index.js +4 -4
  135. package/services/wallet-connect-service/constants.js +3 -3
  136. package/services/wallet-connect-service/helpers.js +1 -4
  137. package/services/wallet-connect-service/index.d.ts +2 -0
  138. package/services/wallet-connect-service/index.js +42 -31
  139. package/storage/index.d.ts +19 -9
  140. package/storage/index.js +115 -23
  141. package/types/common/index.d.ts +1 -0
  142. package/types/common/index.js +4 -0
  143. package/types/common/storage.d.ts +4 -0
  144. package/types/common/storage.js +1 -0
  145. package/types/index.d.ts +1 -0
  146. package/types/index.js +1 -0
  147. package/utils/environment.js +1 -1
  148. package/utils/eth/parseTransaction/index.js +8 -10
  149. package/utils/fetch.d.ts +8 -0
  150. package/utils/fetch.js +44 -0
  151. package/utils/fetchStaticCache.js +2 -3
  152. package/utils/fetchStaticData.d.ts +1 -1
  153. package/utils/fetchStaticData.js +7 -4
  154. package/utils/index.d.ts +2 -0
  155. package/utils/index.js +2 -0
  156. package/utils/reportError.js +0 -1
  157. package/background/handlers/Extension.d.ts +0 -55
  158. package/background/handlers/Extension.js +0 -601
  159. package/background/handlers/Tabs.d.ts +0 -24
  160. package/background/handlers/Tabs.js +0 -194
  161. package/background/handlers/index.d.ts +0 -3
  162. package/background/handlers/index.js +0 -45
  163. package/cjs/background/handlers/Extension.js +0 -642
  164. package/cjs/background/handlers/Tabs.js +0 -222
  165. package/cjs/background/handlers/index.js +0 -54
  166. package/cjs/koni/background/events.js +0 -14
  167. package/koni/background/events.d.ts +0 -1
  168. package/koni/background/events.js +0 -7
@@ -7,7 +7,7 @@ import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCus
7
7
  import { CrowdloanContributionsResponse } from '@subwallet/extension-base/services/subscan-service/types';
8
8
  import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
9
9
  import { WalletConnectNotSupportRequest, WalletConnectSessionRequest } from '@subwallet/extension-base/services/wallet-connect-service/types';
10
- import { BalanceJson, BuyServiceInfo, BuyTokenInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleYieldStepParams, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestGetYieldPoolTargets, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestUnlockDotCheckCanMint, RequestUnlockDotSubscribeMintedData, RequestYieldLeave, RequestYieldStepSubmit, RequestYieldWithdrawal, ResponseEarlyValidateYield, ResponseGetYieldPoolTargets, SubmitYieldStepData, TokenApproveData, UnlockDotTransactionNft, UnstakingStatus, ValidateYieldProcessParams, YieldPoolInfo, YieldPositionInfo, YieldValidationStatus } from '@subwallet/extension-base/types';
10
+ import { BalanceJson, BuyServiceInfo, BuyTokenInfo, EarningRewardHistoryItem, EarningRewardJson, EarningStatus, HandleYieldStepParams, LeavePoolAdditionalData, NominationPoolInfo, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestGetYieldPoolTargets, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestUnlockDotCheckCanMint, RequestUnlockDotSubscribeMintedData, RequestYieldLeave, RequestYieldStepSubmit, RequestYieldWithdrawal, ResponseEarlyValidateYield, ResponseGetYieldPoolTargets, StorageDataInterface, SubmitYieldStepData, TokenApproveData, UnlockDotTransactionNft, UnstakingStatus, ValidateYieldProcessParams, YieldPoolInfo, YieldPositionInfo, YieldValidationStatus } from '@subwallet/extension-base/types';
11
11
  import { SwapErrorType, SwapPair, SwapQuoteResponse, SwapRequest, SwapRequestResult, SwapSubmitParams, SwapTxData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
12
12
  import { InjectedAccount, InjectedAccountWithMeta, MetadataDefBase } from '@subwallet/extension-inject/types';
13
13
  import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
@@ -1887,6 +1887,8 @@ export interface KoniRequestSignatures {
1887
1887
  'pri(database.export)': [null, string];
1888
1888
  'pri(database.import)': [string, boolean];
1889
1889
  'pri(database.exportJson)': [null, DexieExportJsonStructure];
1890
+ 'pri(database.migrateLocalStorage)': [string, boolean];
1891
+ 'pri(database.setLocalStorage)': [StorageDataInterface, boolean];
1890
1892
  'pri(swapService.subscribePairs)': [null, SwapPair[], SwapPair[]];
1891
1893
  'pri(swapService.handleSwapRequest)': [SwapRequest, SwapRequestResult];
1892
1894
  'pri(swapService.handleSwapStep)': [SwapSubmitParams, SWTransactionResponse];
@@ -1,20 +1,8 @@
1
- /// <reference types="chrome" />
2
- import type { MetadataDef, ProviderMeta } from '@subwallet/extension-inject/types';
3
- import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
4
- import type { AccountAuthType, AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types';
5
- import { RequestSettingsType } from '@subwallet/extension-base/background/KoniTypes';
6
- import SettingsStore from '@subwallet/extension-base/stores/Settings';
7
- import { BehaviorSubject } from 'rxjs';
1
+ import type { AccountAuthType } from '../types';
8
2
  export interface Resolver<T> {
9
3
  reject: (error: Error) => void;
10
4
  resolve: (result: T) => void;
11
5
  }
12
- export interface AuthRequest extends Resolver<boolean> {
13
- id: string;
14
- idStr: string;
15
- request: RequestAuthorizeTab;
16
- url: string;
17
- }
18
6
  export declare type AuthUrls = Record<string, AuthUrlInfo>;
19
7
  export interface AuthUrlInfo {
20
8
  count: number;
@@ -26,68 +14,3 @@ export interface AuthUrlInfo {
26
14
  isAllowedMap: Record<string, boolean>;
27
15
  currentEvmNetworkKey?: string;
28
16
  }
29
- interface MetaRequest extends Resolver<boolean> {
30
- id: string;
31
- request: MetadataDef;
32
- url: string;
33
- }
34
- declare type Providers = Record<string, {
35
- meta: ProviderMeta;
36
- start: () => ProviderInterface;
37
- }>;
38
- interface SignRequest extends Resolver<ResponseSigning> {
39
- account: AccountJson;
40
- id: string;
41
- request: RequestSign;
42
- url: string;
43
- }
44
- export declare enum NotificationOptions {
45
- None = 0,
46
- Normal = 1,
47
- PopUp = 2
48
- }
49
- export default class State {
50
- #private;
51
- protected readonly settingsStore: SettingsStore;
52
- readonly authSubject: BehaviorSubject<AuthorizeRequest[]>;
53
- readonly metaSubject: BehaviorSubject<MetadataRequest[]>;
54
- readonly signSubject: BehaviorSubject<SigningRequest[]>;
55
- constructor(providers?: Providers);
56
- get knownMetadata(): MetadataDef[];
57
- get numAuthRequests(): number;
58
- get numMetaRequests(): number;
59
- get numSignRequests(): number;
60
- get allAuthRequests(): AuthorizeRequest[];
61
- get allMetaRequests(): MetadataRequest[];
62
- get allSignRequests(): SigningRequest[];
63
- get authUrls(): AuthUrls;
64
- protected getPopup(): number[];
65
- protected popupClose(): void;
66
- getSettings(update: (value: RequestSettingsType) => void): void;
67
- setSettings(data: RequestSettingsType, callback?: () => void): void;
68
- protected popupOpen(): void;
69
- private authComplete;
70
- private saveCurrentAuthList;
71
- private metaComplete;
72
- private signComplete;
73
- private updateIcon;
74
- toggleAuthorization(url: string): AuthUrls;
75
- private updateIconAuth;
76
- private updateIconMeta;
77
- private updateIconSign;
78
- authorizeUrl(url: string, request: RequestAuthorizeTab): Promise<boolean>;
79
- ensureUrlAuthorized(url: string): boolean;
80
- injectMetadata(url: string, request: MetadataDef): Promise<boolean>;
81
- getAuthRequest(id: string): AuthRequest;
82
- getMetaRequest(id: string): MetaRequest;
83
- getSignRequest(id: string): SignRequest;
84
- rpcListProviders(): Promise<ResponseRpcListProviders>;
85
- rpcSend(request: RequestRpcSend, port: chrome.runtime.Port): Promise<JsonRpcResponse<unknown>>;
86
- rpcStartProvider(key: string, port: chrome.runtime.Port): Promise<ProviderMeta>;
87
- rpcSubscribe({ method, params, type }: RequestRpcSubscribe, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): Promise<number | string>;
88
- rpcSubscribeConnected(_request: null, cb: ProviderInterfaceCallback, port: chrome.runtime.Port): void;
89
- rpcUnsubscribe(request: RequestRpcUnsubscribe, port: chrome.runtime.Port): Promise<boolean>;
90
- saveMetadata(meta: MetadataDef): void;
91
- sign(url: string, request: RequestSign, account: AccountJson): Promise<ResponseSigning>;
92
- }
93
- export {};
@@ -1,428 +1 @@
1
- // Copyright 2019-2022 @polkadot/extension-bg authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { DEFAULT_SETTING } from '@subwallet/extension-base/services/setting-service/constants';
5
- import { SWStorage } from '@subwallet/extension-base/storage';
6
- import SettingsStore from '@subwallet/extension-base/stores/Settings';
7
- import { stripUrl } from '@subwallet/extension-base/utils';
8
- import { getId } from '@subwallet/extension-base/utils/getId';
9
- import { addMetadata, knownMetadata } from '@subwallet/extension-chains';
10
- import { BehaviorSubject } from 'rxjs';
11
- import { knownGenesis } from '@polkadot/networks/defaults';
12
- import { assert } from '@polkadot/util';
13
- import { MetadataStore } from "../../stores/index.js";
14
- import { withErrorLog } from "./helpers.js";
15
- const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
16
- const POPUP_WINDOW_OPTS = {
17
- focused: true,
18
- height: 620,
19
- type: 'popup',
20
- url: NOTIFICATION_URL,
21
- width: 390
22
- };
23
- const NORMAL_WINDOW_OPTS = {
24
- focused: true,
25
- type: 'normal',
26
- url: NOTIFICATION_URL
27
- };
28
- export let NotificationOptions;
29
- (function (NotificationOptions) {
30
- NotificationOptions[NotificationOptions["None"] = 0] = "None";
31
- NotificationOptions[NotificationOptions["Normal"] = 1] = "Normal";
32
- NotificationOptions[NotificationOptions["PopUp"] = 2] = "PopUp";
33
- })(NotificationOptions || (NotificationOptions = {}));
34
- const AUTH_URLS_KEY = 'authUrls';
35
- function extractMetadata(store) {
36
- store.allMap(map => {
37
- const knownEntries = Object.entries(knownGenesis);
38
- const defs = {};
39
- const removals = [];
40
- Object.entries(map).forEach(([key, def]) => {
41
- const entry = knownEntries.find(([, hashes]) => hashes.includes(def.genesisHash));
42
- if (entry) {
43
- const [name, hashes] = entry;
44
- const index = hashes.indexOf(def.genesisHash);
45
-
46
- // flatten the known metadata based on the genesis index
47
- // (lower is better/newer)
48
- if (!defs[name] || defs[name].index > index) {
49
- if (defs[name]) {
50
- // remove the old version of the metadata
51
- removals.push(defs[name].key);
52
- }
53
- defs[name] = {
54
- def,
55
- index,
56
- key
57
- };
58
- }
59
- } else {
60
- // this is not a known entry, so we will just apply it
61
- defs[key] = {
62
- def,
63
- index: 0,
64
- key
65
- };
66
- }
67
- });
68
- removals.forEach(key => store.remove(key));
69
- Object.values(defs).forEach(({
70
- def
71
- }) => addMetadata(def));
72
- });
73
- }
74
- export default class State {
75
- #authUrls = {};
76
- #authRequests = {};
77
- #metaStore = new MetadataStore();
78
- settingsStore = new SettingsStore();
79
-
80
- // Map of providers currently injected in tabs
81
- #injectedProviders = new Map();
82
- #metaRequests = {};
83
-
84
- // Map of all providers exposed by the extension, they are retrievable by key
85
- #providers;
86
- #signRequests = {};
87
- #windows = [];
88
- authSubject = new BehaviorSubject([]);
89
- metaSubject = new BehaviorSubject([]);
90
- signSubject = new BehaviorSubject([]);
91
- constructor(providers = {}) {
92
- this.#providers = providers;
93
- extractMetadata(this.#metaStore);
94
-
95
- // retrieve previously set authorizations
96
- const authString = SWStorage.instance.getItem(AUTH_URLS_KEY) || '{}';
97
- const previousAuth = JSON.parse(authString);
98
- this.#authUrls = previousAuth;
99
- }
100
- get knownMetadata() {
101
- return knownMetadata();
102
- }
103
- get numAuthRequests() {
104
- return Object.keys(this.#authRequests).length;
105
- }
106
- get numMetaRequests() {
107
- return Object.keys(this.#metaRequests).length;
108
- }
109
- get numSignRequests() {
110
- return Object.keys(this.#signRequests).length;
111
- }
112
- get allAuthRequests() {
113
- return Object.values(this.#authRequests).map(({
114
- id,
115
- request,
116
- url
117
- }) => ({
118
- id,
119
- request,
120
- url
121
- }));
122
- }
123
- get allMetaRequests() {
124
- return Object.values(this.#metaRequests).map(({
125
- id,
126
- request,
127
- url
128
- }) => ({
129
- id,
130
- request,
131
- url
132
- }));
133
- }
134
- get allSignRequests() {
135
- return Object.values(this.#signRequests).map(({
136
- account,
137
- id,
138
- request,
139
- url
140
- }) => ({
141
- account,
142
- id,
143
- request,
144
- url
145
- }));
146
- }
147
- get authUrls() {
148
- return this.#authUrls;
149
- }
150
- getPopup() {
151
- return this.#windows;
152
- }
153
- popupClose() {
154
- this.#windows.forEach(id => withErrorLog(() => chrome.windows.remove(id)));
155
- this.#windows = [];
156
- }
157
- getSettings(update) {
158
- this.settingsStore.get('Settings', value => {
159
- if (!value) {
160
- update({
161
- ...DEFAULT_SETTING
162
- });
163
- } else {
164
- update(value);
165
- }
166
- });
167
- }
168
- setSettings(data, callback) {
169
- this.settingsStore.set('Settings', data, callback);
170
- }
171
- popupOpen() {
172
- this.getSettings(({
173
- browserConfirmationType
174
- }) => {
175
- if (browserConfirmationType !== 'extension') {
176
- if (browserConfirmationType === 'window') {
177
- chrome.windows.create(NORMAL_WINDOW_OPTS, window => {
178
- if (window) {
179
- this.#windows.push(window.id || 0);
180
- }
181
- });
182
- }
183
- chrome.windows.getCurrent(win => {
184
- const popupOptions = {
185
- ...POPUP_WINDOW_OPTS
186
- };
187
- if (win) {
188
- popupOptions.left = (win.left || 0) + (win.width || 0) - (POPUP_WINDOW_OPTS.width || 0) - 20;
189
- popupOptions.top = (win.top || 0) + 80;
190
- }
191
- chrome.windows.create(popupOptions, window => {
192
- if (window) {
193
- this.#windows.push(window.id || 0);
194
- }
195
- });
196
- });
197
- }
198
- });
199
- }
200
- authComplete = (id, resolve, reject) => {
201
- const complete = result => {
202
- const isAllowed = result === true;
203
- const {
204
- idStr,
205
- request: {
206
- origin
207
- },
208
- url
209
- } = this.#authRequests[id];
210
- const isAllowedMap = {};
211
- this.#authUrls[stripUrl(url)] = {
212
- count: 0,
213
- id: idStr,
214
- isAllowed,
215
- isAllowedMap,
216
- origin,
217
- url
218
- };
219
- this.saveCurrentAuthList();
220
- delete this.#authRequests[id];
221
- this.updateIconAuth(true);
222
- };
223
- return {
224
- reject: error => {
225
- complete(error);
226
- reject(error);
227
- },
228
- resolve: result => {
229
- complete(result);
230
- resolve(result);
231
- }
232
- };
233
- };
234
- saveCurrentAuthList() {
235
- SWStorage.instance.setItem(AUTH_URLS_KEY, JSON.stringify(this.#authUrls));
236
- }
237
- metaComplete = (id, resolve, reject) => {
238
- const complete = () => {
239
- delete this.#metaRequests[id];
240
- this.updateIconMeta(true);
241
- };
242
- return {
243
- reject: error => {
244
- complete();
245
- reject(error);
246
- },
247
- resolve: result => {
248
- complete();
249
- resolve(result);
250
- }
251
- };
252
- };
253
- signComplete = (id, resolve, reject) => {
254
- const complete = () => {
255
- delete this.#signRequests[id];
256
- this.updateIconSign(true);
257
- };
258
- return {
259
- reject: error => {
260
- complete();
261
- reject(error);
262
- },
263
- resolve: result => {
264
- complete();
265
- resolve(result);
266
- }
267
- };
268
- };
269
- updateIcon(shouldClose) {
270
- const authCount = this.numAuthRequests;
271
- const metaCount = this.numMetaRequests;
272
- const signCount = this.numSignRequests;
273
- const text = authCount ? 'Auth' : metaCount ? 'Meta' : signCount ? `${signCount}` : '';
274
- withErrorLog(() => {
275
- var _chrome$browserAction;
276
- return (_chrome$browserAction = chrome.browserAction) === null || _chrome$browserAction === void 0 ? void 0 : _chrome$browserAction.setBadgeText({
277
- text
278
- });
279
- });
280
- if (shouldClose && text === '') {
281
- this.popupClose();
282
- }
283
- }
284
- toggleAuthorization(url) {
285
- const entry = this.#authUrls[url];
286
- assert(entry, `The source ${url} is not known`);
287
- this.#authUrls[url].isAllowed = !entry.isAllowed;
288
- this.saveCurrentAuthList();
289
- return this.#authUrls;
290
- }
291
- updateIconAuth(shouldClose) {
292
- this.authSubject.next(this.allAuthRequests);
293
- this.updateIcon(shouldClose);
294
- }
295
- updateIconMeta(shouldClose) {
296
- this.metaSubject.next(this.allMetaRequests);
297
- this.updateIcon(shouldClose);
298
- }
299
- updateIconSign(shouldClose) {
300
- this.signSubject.next(this.allSignRequests);
301
- this.updateIcon(shouldClose);
302
- }
303
- async authorizeUrl(url, request) {
304
- const idStr = stripUrl(url);
305
-
306
- // Do not enqueue duplicate authorization requests.
307
- const isDuplicate = Object.values(this.#authRequests).some(request => request.idStr === idStr);
308
- assert(!isDuplicate, 'The source {{url}} has a pending authorization request'.replace('{{url}}', url));
309
- if (this.#authUrls[idStr]) {
310
- // this url was seen in the past
311
- assert(this.#authUrls[idStr].isAllowed, 'The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
312
- return false;
313
- }
314
- return new Promise((resolve, reject) => {
315
- const id = getId();
316
- this.#authRequests[id] = {
317
- ...this.authComplete(id, resolve, reject),
318
- id,
319
- idStr,
320
- request,
321
- url
322
- };
323
- this.updateIconAuth();
324
- this.popupOpen();
325
- });
326
- }
327
- ensureUrlAuthorized(url) {
328
- const entry = this.#authUrls[stripUrl(url)];
329
- assert(entry, 'The source {{url}} has not been authorized yet'.replace('{{url}}', url));
330
- assert(entry.isAllowed, 'The source {{url}} is not allowed to interact with this extension'.replace('{{url}}', url));
331
- return true;
332
- }
333
- injectMetadata(url, request) {
334
- return new Promise((resolve, reject) => {
335
- const id = getId();
336
- this.#metaRequests[id] = {
337
- ...this.metaComplete(id, resolve, reject),
338
- id,
339
- request,
340
- url
341
- };
342
- this.updateIconMeta();
343
- this.popupOpen();
344
- });
345
- }
346
- getAuthRequest(id) {
347
- return this.#authRequests[id];
348
- }
349
- getMetaRequest(id) {
350
- return this.#metaRequests[id];
351
- }
352
- getSignRequest(id) {
353
- return this.#signRequests[id];
354
- }
355
-
356
- // List all providers the extension is exposing
357
- rpcListProviders() {
358
- return Promise.resolve(Object.keys(this.#providers).reduce((acc, key) => {
359
- acc[key] = this.#providers[key].meta;
360
- return acc;
361
- }, {}));
362
- }
363
- rpcSend(request, port) {
364
- const provider = this.#injectedProviders.get(port);
365
- assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
366
- return provider.send(request.method, request.params);
367
- }
368
-
369
- // Start a provider, return its meta
370
- rpcStartProvider(key, port) {
371
- assert(Object.keys(this.#providers).includes(key), 'Provider cannot be found.');
372
- if (this.#injectedProviders.get(port)) {
373
- return Promise.resolve(this.#providers[key].meta);
374
- }
375
-
376
- // Instantiate the provider
377
- this.#injectedProviders.set(port, this.#providers[key].start());
378
-
379
- // Close provider connection when page is closed
380
- port.onDisconnect.addListener(() => {
381
- const provider = this.#injectedProviders.get(port);
382
- if (provider) {
383
- withErrorLog(() => provider.disconnect());
384
- }
385
- this.#injectedProviders.delete(port);
386
- });
387
- return Promise.resolve(this.#providers[key].meta);
388
- }
389
- rpcSubscribe({
390
- method,
391
- params,
392
- type
393
- }, cb, port) {
394
- const provider = this.#injectedProviders.get(port);
395
- assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
396
- return provider.subscribe(type, method, params, cb);
397
- }
398
- rpcSubscribeConnected(_request, cb, port) {
399
- const provider = this.#injectedProviders.get(port);
400
- assert(provider, 'Cannot call pub(rpc.subscribeConnected) before provider is set');
401
- cb(null, provider.isConnected); // Immediately send back current isConnected
402
- provider.on('connected', () => cb(null, true));
403
- provider.on('disconnected', () => cb(null, false));
404
- }
405
- rpcUnsubscribe(request, port) {
406
- const provider = this.#injectedProviders.get(port);
407
- assert(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
408
- return provider.unsubscribe(request.type, request.method, request.subscriptionId);
409
- }
410
- saveMetadata(meta) {
411
- this.#metaStore.set(meta.genesisHash, meta);
412
- addMetadata(meta);
413
- }
414
- sign(url, request, account) {
415
- const id = getId();
416
- return new Promise((resolve, reject) => {
417
- this.#signRequests[id] = {
418
- ...this.signComplete(id, resolve, reject),
419
- account,
420
- id,
421
- request,
422
- url
423
- };
424
- this.updateIconSign();
425
- this.popupOpen();
426
- });
427
- }
428
- }
1
+ export {};
@@ -93,6 +93,7 @@ export interface SigningRequest extends ConfirmationRequestBase {
93
93
  request: RequestSign;
94
94
  }
95
95
  export interface RequestSignatures extends KoniRequestSignatures {
96
+ 'pri(ping)': [null, string];
96
97
  'pri(accounts.create.external)': [RequestAccountCreateExternal, boolean];
97
98
  'pri(accounts.create.hardware)': [RequestAccountCreateHardware, boolean];
98
99
  'pri(accounts.create.suri)': [RequestAccountCreateSuri, boolean];