@polkadot/extension-base 0.45.5 → 0.46.2

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.
@@ -1,8 +1,8 @@
1
1
  import type { KeyringPair } from '@polkadot/keyring/types';
2
+ import type { TypeRegistry } from '@polkadot/types';
2
3
  import type { SignerPayloadRaw } from '@polkadot/types/types';
3
4
  import type { HexString } from '@polkadot/util/types';
4
5
  import type { RequestSign } from './types.js';
5
- import { TypeRegistry } from '@polkadot/types';
6
6
  export default class RequestBytesSign implements RequestSign {
7
7
  readonly payload: SignerPayloadRaw;
8
8
  constructor(payload: SignerPayloadRaw);
@@ -1,8 +1,8 @@
1
1
  import type { KeyringPair } from '@polkadot/keyring/types';
2
+ import type { TypeRegistry } from '@polkadot/types';
2
3
  import type { SignerPayloadJSON } from '@polkadot/types/types';
3
4
  import type { HexString } from '@polkadot/util/types';
4
5
  import type { RequestSign } from './types.js';
5
- import { TypeRegistry } from '@polkadot/types';
6
6
  export default class RequestExtrinsicSign implements RequestSign {
7
7
  readonly payload: SignerPayloadJSON;
8
8
  constructor(payload: SignerPayloadJSON);
@@ -1,6 +1,6 @@
1
1
  /// <reference types="chrome" />
2
2
  import type { MessageTypes, RequestTypes, ResponseType } from '../types.js';
3
- import State from './State.js';
3
+ import type State from './State.js';
4
4
  export default class Extension {
5
5
  #private;
6
6
  constructor(state: State);
@@ -1,5 +1,3 @@
1
- var _Extension_cachedUnlocks, _Extension_state;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { ALLOWED_PATH, PASSWORD_EXPIRY_MS } from '@polkadot/extension-base/defaults';
4
2
  import { metadataExpand } from '@polkadot/extension-chains';
5
3
  import { TypeRegistry } from '@polkadot/types';
@@ -22,15 +20,13 @@ function isJsonPayload(value) {
22
20
  }
23
21
  export default class Extension {
24
22
  constructor(state) {
25
- _Extension_cachedUnlocks.set(this, void 0);
26
- _Extension_state.set(this, void 0);
27
- __classPrivateFieldSet(this, _Extension_cachedUnlocks, {}, "f");
28
- __classPrivateFieldSet(this, _Extension_state, state, "f");
23
+ this.__internal__cachedUnlocks = {};
24
+ this.__internal__state = state;
29
25
  }
30
26
  transformAccounts(accounts) {
31
27
  return Object.values(accounts).map(({ json: { address, meta }, type }) => ({
32
28
  address,
33
- isDefaultAuthSelected: __classPrivateFieldGet(this, _Extension_state, "f").defaultAuthAccountSelection.includes(address),
29
+ isDefaultAuthSelected: this.__internal__state.defaultAuthAccountSelection.includes(address),
34
30
  ...meta,
35
31
  type
36
32
  }));
@@ -79,25 +75,25 @@ export default class Extension {
79
75
  accountsForget({ address }) {
80
76
  const authorizedAccountsDiff = [];
81
77
  // cycle through authUrls and prepare the array of diff
82
- Object.entries(__classPrivateFieldGet(this, _Extension_state, "f").authUrls).forEach(([url, urlInfo]) => {
78
+ Object.entries(this.__internal__state.authUrls).forEach(([url, urlInfo]) => {
83
79
  if (!urlInfo.authorizedAccounts.includes(address)) {
84
80
  return;
85
81
  }
86
82
  authorizedAccountsDiff.push([url, urlInfo.authorizedAccounts.filter((previousAddress) => previousAddress !== address)]);
87
83
  });
88
- __classPrivateFieldGet(this, _Extension_state, "f").updateAuthorizedAccounts(authorizedAccountsDiff);
84
+ this.__internal__state.updateAuthorizedAccounts(authorizedAccountsDiff);
89
85
  // cycle through default account selection for auth and remove any occurence of the account
90
- const newDefaultAuthAccounts = __classPrivateFieldGet(this, _Extension_state, "f").defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
91
- __classPrivateFieldGet(this, _Extension_state, "f").updateDefaultAuthAccounts(newDefaultAuthAccounts);
86
+ const newDefaultAuthAccounts = this.__internal__state.defaultAuthAccountSelection.filter((defaultSelectionAddress) => defaultSelectionAddress !== address);
87
+ this.__internal__state.updateDefaultAuthAccounts(newDefaultAuthAccounts);
92
88
  keyring.forgetAccount(address);
93
89
  return true;
94
90
  }
95
91
  refreshAccountPasswordCache(pair) {
96
92
  const { address } = pair;
97
- const savedExpiry = __classPrivateFieldGet(this, _Extension_cachedUnlocks, "f")[address] || 0;
93
+ const savedExpiry = this.__internal__cachedUnlocks[address] || 0;
98
94
  const remainingTime = savedExpiry - Date.now();
99
95
  if (remainingTime < 0) {
100
- __classPrivateFieldGet(this, _Extension_cachedUnlocks, "f")[address] = 0;
96
+ this.__internal__cachedUnlocks[address] = 0;
101
97
  pair.lock();
102
98
  return 0;
103
99
  }
@@ -134,22 +130,22 @@ export default class Extension {
134
130
  return true;
135
131
  }
136
132
  authorizeApprove({ authorizedAccounts, id }) {
137
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getAuthRequest(id);
133
+ const queued = this.__internal__state.getAuthRequest(id);
138
134
  assert(queued, 'Unable to find request');
139
135
  const { resolve } = queued;
140
136
  resolve({ authorizedAccounts, result: true });
141
137
  return true;
142
138
  }
143
139
  authorizeUpdate({ authorizedAccounts, url }) {
144
- return __classPrivateFieldGet(this, _Extension_state, "f").updateAuthorizedAccounts([[url, authorizedAccounts]]);
140
+ return this.__internal__state.updateAuthorizedAccounts([[url, authorizedAccounts]]);
145
141
  }
146
142
  getAuthList() {
147
- return { list: __classPrivateFieldGet(this, _Extension_state, "f").authUrls };
143
+ return { list: this.__internal__state.authUrls };
148
144
  }
149
145
  // FIXME This looks very much like what we have in accounts
150
146
  authorizeSubscribe(id, port) {
151
147
  const cb = createSubscription(id, port);
152
- const subscription = __classPrivateFieldGet(this, _Extension_state, "f").authSubject.subscribe((requests) => cb(requests));
148
+ const subscription = this.__internal__state.authSubject.subscribe((requests) => cb(requests));
153
149
  port.onDisconnect.addListener(() => {
154
150
  unsubscribe(id);
155
151
  subscription.unsubscribe();
@@ -157,21 +153,21 @@ export default class Extension {
157
153
  return true;
158
154
  }
159
155
  metadataApprove({ id }) {
160
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getMetaRequest(id);
156
+ const queued = this.__internal__state.getMetaRequest(id);
161
157
  assert(queued, 'Unable to find request');
162
158
  const { request, resolve } = queued;
163
- __classPrivateFieldGet(this, _Extension_state, "f").saveMetadata(request);
159
+ this.__internal__state.saveMetadata(request);
164
160
  resolve(true);
165
161
  return true;
166
162
  }
167
163
  metadataGet(genesisHash) {
168
- return __classPrivateFieldGet(this, _Extension_state, "f").knownMetadata.find((result) => result.genesisHash === genesisHash) || null;
164
+ return this.__internal__state.knownMetadata.find((result) => result.genesisHash === genesisHash) || null;
169
165
  }
170
166
  metadataList() {
171
- return __classPrivateFieldGet(this, _Extension_state, "f").knownMetadata;
167
+ return this.__internal__state.knownMetadata;
172
168
  }
173
169
  metadataReject({ id }) {
174
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getMetaRequest(id);
170
+ const queued = this.__internal__state.getMetaRequest(id);
175
171
  assert(queued, 'Unable to find request');
176
172
  const { reject } = queued;
177
173
  reject(new Error('Rejected'));
@@ -179,7 +175,7 @@ export default class Extension {
179
175
  }
180
176
  metadataSubscribe(id, port) {
181
177
  const cb = createSubscription(id, port);
182
- const subscription = __classPrivateFieldGet(this, _Extension_state, "f").metaSubject.subscribe((requests) => cb(requests));
178
+ const subscription = this.__internal__state.metaSubject.subscribe((requests) => cb(requests));
183
179
  port.onDisconnect.addListener(() => {
184
180
  unsubscribe(id);
185
181
  subscription.unsubscribe();
@@ -240,7 +236,7 @@ export default class Extension {
240
236
  };
241
237
  }
242
238
  signingApprovePassword({ id, password, savePass }) {
243
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getSignRequest(id);
239
+ const queued = this.__internal__state.getSignRequest(id);
244
240
  assert(queued, 'Unable to find request');
245
241
  const { reject, request, resolve } = queued;
246
242
  const pair = keyring.getPair(queued.account.address);
@@ -261,7 +257,7 @@ export default class Extension {
261
257
  const { payload } = request;
262
258
  if (isJsonPayload(payload)) {
263
259
  // Get the metadata for the genesisHash
264
- const metadata = __classPrivateFieldGet(this, _Extension_state, "f").knownMetadata.find(({ genesisHash }) => genesisHash === payload.genesisHash);
260
+ const metadata = this.__internal__state.knownMetadata.find(({ genesisHash }) => genesisHash === payload.genesisHash);
265
261
  if (metadata) {
266
262
  // we have metadata, expand it and extract the info/registry
267
263
  const expanded = metadataExpand(metadata, false);
@@ -283,7 +279,7 @@ export default class Extension {
283
279
  // unlike queued.account.address the following
284
280
  // address is encoded with the default prefix
285
281
  // which what is used for password caching mapping
286
- __classPrivateFieldGet(this, _Extension_cachedUnlocks, "f")[pair.address] = Date.now() + PASSWORD_EXPIRY_MS;
282
+ this.__internal__cachedUnlocks[pair.address] = Date.now() + PASSWORD_EXPIRY_MS;
287
283
  }
288
284
  else {
289
285
  pair.lock();
@@ -295,21 +291,21 @@ export default class Extension {
295
291
  return true;
296
292
  }
297
293
  signingApproveSignature({ id, signature }) {
298
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getSignRequest(id);
294
+ const queued = this.__internal__state.getSignRequest(id);
299
295
  assert(queued, 'Unable to find request');
300
296
  const { resolve } = queued;
301
297
  resolve({ id, signature });
302
298
  return true;
303
299
  }
304
300
  signingCancel({ id }) {
305
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getSignRequest(id);
301
+ const queued = this.__internal__state.getSignRequest(id);
306
302
  assert(queued, 'Unable to find request');
307
303
  const { reject } = queued;
308
304
  reject(new Error('Cancelled'));
309
305
  return true;
310
306
  }
311
307
  signingIsLocked({ id }) {
312
- const queued = __classPrivateFieldGet(this, _Extension_state, "f").getSignRequest(id);
308
+ const queued = this.__internal__state.getSignRequest(id);
313
309
  assert(queued, 'Unable to find request');
314
310
  const address = queued.request.payload.address;
315
311
  const pair = keyring.getPair(address);
@@ -323,7 +319,7 @@ export default class Extension {
323
319
  // FIXME This looks very much like what we have in authorization
324
320
  signingSubscribe(id, port) {
325
321
  const cb = createSubscription(id, port);
326
- const subscription = __classPrivateFieldGet(this, _Extension_state, "f").signSubject.subscribe((requests) => cb(requests));
322
+ const subscription = this.__internal__state.signSubject.subscribe((requests) => cb(requests));
327
323
  port.onDisconnect.addListener(() => {
328
324
  unsubscribe(id);
329
325
  subscription.unsubscribe();
@@ -372,16 +368,16 @@ export default class Extension {
372
368
  return true;
373
369
  }
374
370
  removeAuthorization(url) {
375
- return { list: __classPrivateFieldGet(this, _Extension_state, "f").removeAuthorization(url) };
371
+ return { list: this.__internal__state.removeAuthorization(url) };
376
372
  }
377
373
  deleteAuthRequest(requestId) {
378
- return __classPrivateFieldGet(this, _Extension_state, "f").deleteAuthRequest(requestId);
374
+ return this.__internal__state.deleteAuthRequest(requestId);
379
375
  }
380
376
  updateCurrentTabs({ urls }) {
381
- __classPrivateFieldGet(this, _Extension_state, "f").udateCurrentTabsUrl(urls);
377
+ this.__internal__state.udateCurrentTabsUrl(urls);
382
378
  }
383
379
  getConnectedTabsUrl() {
384
- return __classPrivateFieldGet(this, _Extension_state, "f").getConnectedTabsUrl();
380
+ return this.__internal__state.getConnectedTabsUrl();
385
381
  }
386
382
  // Weird thought, the eslint override is not needed in Tabs
387
383
  // eslint-disable-next-line @typescript-eslint/require-await
@@ -454,7 +450,7 @@ export default class Extension {
454
450
  case 'pri(seed.validate)':
455
451
  return this.seedValidate(request);
456
452
  case 'pri(settings.notification)':
457
- return __classPrivateFieldGet(this, _Extension_state, "f").setNotification(request);
453
+ return this.__internal__state.setNotification(request);
458
454
  case 'pri(signing.approve.password)':
459
455
  return this.signingApprovePassword(request);
460
456
  case 'pri(signing.approve.signature)':
@@ -472,4 +468,3 @@ export default class Extension {
472
468
  }
473
469
  }
474
470
  }
475
- _Extension_cachedUnlocks = new WeakMap(), _Extension_state = new WeakMap();
@@ -1,7 +1,7 @@
1
1
  /// <reference types="chrome" />
2
2
  import type { MetadataDef, ProviderMeta } from '@polkadot/extension-inject/types';
3
3
  import type { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
4
- import type { AccountJson, AuthorizeRequest, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types.js';
4
+ import type { AccountJson, AuthorizeRequest, AuthUrlInfo, AuthUrls, MetadataRequest, RequestAuthorizeTab, RequestRpcSend, RequestRpcSubscribe, RequestRpcUnsubscribe, RequestSign, ResponseRpcListProviders, ResponseSigning, SigningRequest } from '../types.js';
5
5
  import { BehaviorSubject } from 'rxjs';
6
6
  interface Resolver<T> {
7
7
  reject: (error: Error) => void;
@@ -13,16 +13,7 @@ interface AuthRequest extends Resolver<AuthResponse> {
13
13
  request: RequestAuthorizeTab;
14
14
  url: string;
15
15
  }
16
- export type AuthUrls = Record<string, AuthUrlInfo>;
17
16
  export type AuthorizedAccountsDiff = [url: string, authorizedAccounts: AuthUrlInfo['authorizedAccounts']][];
18
- export interface AuthUrlInfo {
19
- count: number;
20
- id: string;
21
- isAllowed?: boolean;
22
- origin: string;
23
- url: string;
24
- authorizedAccounts: string[];
25
- }
26
17
  interface MetaRequest extends Resolver<boolean> {
27
18
  id: string;
28
19
  request: MetadataDef;
@@ -1,12 +1,10 @@
1
- var _State_authUrls, _State_authRequests, _State_metaStore, _State_injectedProviders, _State_metaRequests, _State_notification, _State_providers, _State_signRequests, _State_windows, _State_connectedTabsUrl;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
1
  import { BehaviorSubject } from 'rxjs';
4
- import { getId } from '@polkadot/extension-base/utils/getId';
5
2
  import { addMetadata, knownMetadata } from '@polkadot/extension-chains';
6
3
  import { knownGenesis } from '@polkadot/networks/defaults';
7
4
  import settings from '@polkadot/ui-settings';
8
5
  import { assert } from '@polkadot/util';
9
6
  import { MetadataStore } from '../../stores/index.js';
7
+ import { getId } from '../../utils/getId.js';
10
8
  import { withErrorLog } from './helpers.js';
11
9
  const NOTIFICATION_URL = chrome.extension.getURL('notification.html');
12
10
  const POPUP_WINDOW_OPTS = {
@@ -64,26 +62,24 @@ function extractMetadata(store) {
64
62
  }
65
63
  export default class State {
66
64
  constructor(providers = {}) {
67
- _State_authUrls.set(this, {});
68
- _State_authRequests.set(this, {});
69
- _State_metaStore.set(this, new MetadataStore());
65
+ this.__internal__authUrls = {};
66
+ this.__internal__authRequests = {};
67
+ this.__internal__metaStore = new MetadataStore();
70
68
  // Map of providers currently injected in tabs
71
- _State_injectedProviders.set(this, new Map());
72
- _State_metaRequests.set(this, {});
73
- _State_notification.set(this, settings.notification);
74
- // Map of all providers exposed by the extension, they are retrievable by key
75
- _State_providers.set(this, void 0);
76
- _State_signRequests.set(this, {});
77
- _State_windows.set(this, []);
78
- _State_connectedTabsUrl.set(this, []);
69
+ this.__internal__injectedProviders = new Map();
70
+ this.__internal__metaRequests = {};
71
+ this.__internal__notification = settings.notification;
72
+ this.__internal__signRequests = {};
73
+ this.__internal__windows = [];
74
+ this.__internal__connectedTabsUrl = [];
79
75
  this.authSubject = new BehaviorSubject([]);
80
76
  this.metaSubject = new BehaviorSubject([]);
81
77
  this.signSubject = new BehaviorSubject([]);
82
78
  this.defaultAuthAccountSelection = [];
83
79
  this.authComplete = (id, resolve, reject) => {
84
80
  const complete = (authorizedAccounts = []) => {
85
- const { idStr, request: { origin }, url } = __classPrivateFieldGet(this, _State_authRequests, "f")[id];
86
- __classPrivateFieldGet(this, _State_authUrls, "f")[this.stripUrl(url)] = {
81
+ const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
82
+ this.__internal__authUrls[this.stripUrl(url)] = {
87
83
  authorizedAccounts,
88
84
  count: 0,
89
85
  id: idStr,
@@ -92,7 +88,7 @@ export default class State {
92
88
  };
93
89
  this.saveCurrentAuthList();
94
90
  this.updateDefaultAuthAccounts(authorizedAccounts);
95
- delete __classPrivateFieldGet(this, _State_authRequests, "f")[id];
91
+ delete this.__internal__authRequests[id];
96
92
  this.updateIconAuth(true);
97
93
  };
98
94
  return {
@@ -108,7 +104,7 @@ export default class State {
108
104
  };
109
105
  this.metaComplete = (id, resolve, reject) => {
110
106
  const complete = () => {
111
- delete __classPrivateFieldGet(this, _State_metaRequests, "f")[id];
107
+ delete this.__internal__metaRequests[id];
112
108
  this.updateIconMeta(true);
113
109
  };
114
110
  return {
@@ -124,7 +120,7 @@ export default class State {
124
120
  };
125
121
  this.signComplete = (id, resolve, reject) => {
126
122
  const complete = () => {
127
- delete __classPrivateFieldGet(this, _State_signRequests, "f")[id];
123
+ delete this.__internal__signRequests[id];
128
124
  this.updateIconSign(true);
129
125
  };
130
126
  return {
@@ -138,12 +134,12 @@ export default class State {
138
134
  }
139
135
  };
140
136
  };
141
- __classPrivateFieldSet(this, _State_providers, providers, "f");
142
- extractMetadata(__classPrivateFieldGet(this, _State_metaStore, "f"));
137
+ this.__internal__providers = providers;
138
+ extractMetadata(this.__internal__metaStore);
143
139
  // retrieve previously set authorizations
144
140
  const authString = localStorage.getItem(AUTH_URLS_KEY) || '{}';
145
141
  const previousAuth = JSON.parse(authString);
146
- __classPrivateFieldSet(this, _State_authUrls, previousAuth, "f");
142
+ this.__internal__authUrls = previousAuth;
147
143
  // retrieve previously set default auth accounts
148
144
  const defaultAuthString = localStorage.getItem(DEFAULT_AUTH_ACCOUNTS) || '[]';
149
145
  const previousDefaultAuth = JSON.parse(defaultAuthString);
@@ -153,43 +149,43 @@ export default class State {
153
149
  return knownMetadata();
154
150
  }
155
151
  get numAuthRequests() {
156
- return Object.keys(__classPrivateFieldGet(this, _State_authRequests, "f")).length;
152
+ return Object.keys(this.__internal__authRequests).length;
157
153
  }
158
154
  get numMetaRequests() {
159
- return Object.keys(__classPrivateFieldGet(this, _State_metaRequests, "f")).length;
155
+ return Object.keys(this.__internal__metaRequests).length;
160
156
  }
161
157
  get numSignRequests() {
162
- return Object.keys(__classPrivateFieldGet(this, _State_signRequests, "f")).length;
158
+ return Object.keys(this.__internal__signRequests).length;
163
159
  }
164
160
  get allAuthRequests() {
165
161
  return Object
166
- .values(__classPrivateFieldGet(this, _State_authRequests, "f"))
162
+ .values(this.__internal__authRequests)
167
163
  .map(({ id, request, url }) => ({ id, request, url }));
168
164
  }
169
165
  get allMetaRequests() {
170
166
  return Object
171
- .values(__classPrivateFieldGet(this, _State_metaRequests, "f"))
167
+ .values(this.__internal__metaRequests)
172
168
  .map(({ id, request, url }) => ({ id, request, url }));
173
169
  }
174
170
  get allSignRequests() {
175
171
  return Object
176
- .values(__classPrivateFieldGet(this, _State_signRequests, "f"))
172
+ .values(this.__internal__signRequests)
177
173
  .map(({ account, id, request, url }) => ({ account, id, request, url }));
178
174
  }
179
175
  get authUrls() {
180
- return __classPrivateFieldGet(this, _State_authUrls, "f");
176
+ return this.__internal__authUrls;
181
177
  }
182
178
  popupClose() {
183
- __classPrivateFieldGet(this, _State_windows, "f").forEach((id) => withErrorLog(() => chrome.windows.remove(id)));
184
- __classPrivateFieldSet(this, _State_windows, [], "f");
179
+ this.__internal__windows.forEach((id) => withErrorLog(() => chrome.windows.remove(id)));
180
+ this.__internal__windows = [];
185
181
  }
186
182
  popupOpen() {
187
- __classPrivateFieldGet(this, _State_notification, "f") !== 'extension' &&
188
- chrome.windows.create(__classPrivateFieldGet(this, _State_notification, "f") === 'window'
183
+ this.__internal__notification !== 'extension' &&
184
+ chrome.windows.create(this.__internal__notification === 'window'
189
185
  ? NORMAL_WINDOW_OPTS
190
186
  : POPUP_WINDOW_OPTS, (window) => {
191
187
  if (window) {
192
- __classPrivateFieldGet(this, _State_windows, "f").push(window.id || 0);
188
+ this.__internal__windows.push(window.id || 0);
193
189
  }
194
190
  });
195
191
  }
@@ -209,17 +205,17 @@ export default class State {
209
205
  : undefined;
210
206
  })
211
207
  .filter((value) => !!value);
212
- __classPrivateFieldSet(this, _State_connectedTabsUrl, connectedTabs, "f");
208
+ this.__internal__connectedTabsUrl = connectedTabs;
213
209
  }
214
210
  getConnectedTabsUrl() {
215
- return __classPrivateFieldGet(this, _State_connectedTabsUrl, "f");
211
+ return this.__internal__connectedTabsUrl;
216
212
  }
217
213
  deleteAuthRequest(requestId) {
218
- delete __classPrivateFieldGet(this, _State_authRequests, "f")[requestId];
214
+ delete this.__internal__authRequests[requestId];
219
215
  this.updateIconAuth(true);
220
216
  }
221
217
  saveCurrentAuthList() {
222
- localStorage.setItem(AUTH_URLS_KEY, JSON.stringify(__classPrivateFieldGet(this, _State_authUrls, "f")));
218
+ localStorage.setItem(AUTH_URLS_KEY, JSON.stringify(this.__internal__authUrls));
223
219
  }
224
220
  saveDefaultAuthAccounts() {
225
221
  localStorage.setItem(DEFAULT_AUTH_ACCOUNTS, JSON.stringify(this.defaultAuthAccountSelection));
@@ -248,11 +244,11 @@ export default class State {
248
244
  }
249
245
  }
250
246
  removeAuthorization(url) {
251
- const entry = __classPrivateFieldGet(this, _State_authUrls, "f")[url];
247
+ const entry = this.__internal__authUrls[url];
252
248
  assert(entry, `The source ${url} is not known`);
253
- delete __classPrivateFieldGet(this, _State_authUrls, "f")[url];
249
+ delete this.__internal__authUrls[url];
254
250
  this.saveCurrentAuthList();
255
- return __classPrivateFieldGet(this, _State_authUrls, "f");
251
+ return this.__internal__authUrls;
256
252
  }
257
253
  updateIconAuth(shouldClose) {
258
254
  this.authSubject.next(this.allAuthRequests);
@@ -268,7 +264,7 @@ export default class State {
268
264
  }
269
265
  updateAuthorizedAccounts(authorizedAccountDiff) {
270
266
  authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
271
- __classPrivateFieldGet(this, _State_authUrls, "f")[url].authorizedAccounts = authorizedAccountDiff;
267
+ this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
272
268
  });
273
269
  this.saveCurrentAuthList();
274
270
  }
@@ -276,12 +272,12 @@ export default class State {
276
272
  const idStr = this.stripUrl(url);
277
273
  // Do not enqueue duplicate authorization requests.
278
274
  const isDuplicate = Object
279
- .values(__classPrivateFieldGet(this, _State_authRequests, "f"))
275
+ .values(this.__internal__authRequests)
280
276
  .some((request) => request.idStr === idStr);
281
277
  assert(!isDuplicate, `The source ${url} has a pending authorization request`);
282
- if (__classPrivateFieldGet(this, _State_authUrls, "f")[idStr]) {
278
+ if (this.__internal__authUrls[idStr]) {
283
279
  // this url was seen in the past
284
- assert(__classPrivateFieldGet(this, _State_authUrls, "f")[idStr].authorizedAccounts || __classPrivateFieldGet(this, _State_authUrls, "f")[idStr].isAllowed, `The source ${url} is not allowed to interact with this extension`);
280
+ assert(this.__internal__authUrls[idStr].authorizedAccounts || this.__internal__authUrls[idStr].isAllowed, `The source ${url} is not allowed to interact with this extension`);
285
281
  return {
286
282
  authorizedAccounts: [],
287
283
  result: false
@@ -289,7 +285,7 @@ export default class State {
289
285
  }
290
286
  return new Promise((resolve, reject) => {
291
287
  const id = getId();
292
- __classPrivateFieldGet(this, _State_authRequests, "f")[id] = {
288
+ this.__internal__authRequests[id] = {
293
289
  ...this.authComplete(id, resolve, reject),
294
290
  id,
295
291
  idStr,
@@ -301,14 +297,14 @@ export default class State {
301
297
  });
302
298
  }
303
299
  ensureUrlAuthorized(url) {
304
- const entry = __classPrivateFieldGet(this, _State_authUrls, "f")[this.stripUrl(url)];
300
+ const entry = this.__internal__authUrls[this.stripUrl(url)];
305
301
  assert(entry, `The source ${url} has not been enabled yet`);
306
302
  return true;
307
303
  }
308
304
  injectMetadata(url, request) {
309
305
  return new Promise((resolve, reject) => {
310
306
  const id = getId();
311
- __classPrivateFieldGet(this, _State_metaRequests, "f")[id] = {
307
+ this.__internal__metaRequests[id] = {
312
308
  ...this.metaComplete(id, resolve, reject),
313
309
  id,
314
310
  request,
@@ -319,73 +315,73 @@ export default class State {
319
315
  });
320
316
  }
321
317
  getAuthRequest(id) {
322
- return __classPrivateFieldGet(this, _State_authRequests, "f")[id];
318
+ return this.__internal__authRequests[id];
323
319
  }
324
320
  getMetaRequest(id) {
325
- return __classPrivateFieldGet(this, _State_metaRequests, "f")[id];
321
+ return this.__internal__metaRequests[id];
326
322
  }
327
323
  getSignRequest(id) {
328
- return __classPrivateFieldGet(this, _State_signRequests, "f")[id];
324
+ return this.__internal__signRequests[id];
329
325
  }
330
326
  // List all providers the extension is exposing
331
327
  rpcListProviders() {
332
- return Promise.resolve(Object.keys(__classPrivateFieldGet(this, _State_providers, "f")).reduce((acc, key) => {
333
- acc[key] = __classPrivateFieldGet(this, _State_providers, "f")[key].meta;
328
+ return Promise.resolve(Object.keys(this.__internal__providers).reduce((acc, key) => {
329
+ acc[key] = this.__internal__providers[key].meta;
334
330
  return acc;
335
331
  }, {}));
336
332
  }
337
333
  rpcSend(request, port) {
338
- const provider = __classPrivateFieldGet(this, _State_injectedProviders, "f").get(port);
334
+ const provider = this.__internal__injectedProviders.get(port);
339
335
  assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
340
336
  return provider.send(request.method, request.params);
341
337
  }
342
338
  // Start a provider, return its meta
343
339
  rpcStartProvider(key, port) {
344
- assert(Object.keys(__classPrivateFieldGet(this, _State_providers, "f")).includes(key), `Provider ${key} is not exposed by extension`);
345
- if (__classPrivateFieldGet(this, _State_injectedProviders, "f").get(port)) {
346
- return Promise.resolve(__classPrivateFieldGet(this, _State_providers, "f")[key].meta);
340
+ assert(Object.keys(this.__internal__providers).includes(key), `Provider ${key} is not exposed by extension`);
341
+ if (this.__internal__injectedProviders.get(port)) {
342
+ return Promise.resolve(this.__internal__providers[key].meta);
347
343
  }
348
344
  // Instantiate the provider
349
- __classPrivateFieldGet(this, _State_injectedProviders, "f").set(port, __classPrivateFieldGet(this, _State_providers, "f")[key].start());
345
+ this.__internal__injectedProviders.set(port, this.__internal__providers[key].start());
350
346
  // Close provider connection when page is closed
351
347
  port.onDisconnect.addListener(() => {
352
- const provider = __classPrivateFieldGet(this, _State_injectedProviders, "f").get(port);
348
+ const provider = this.__internal__injectedProviders.get(port);
353
349
  if (provider) {
354
350
  withErrorLog(() => provider.disconnect());
355
351
  }
356
- __classPrivateFieldGet(this, _State_injectedProviders, "f").delete(port);
352
+ this.__internal__injectedProviders.delete(port);
357
353
  });
358
- return Promise.resolve(__classPrivateFieldGet(this, _State_providers, "f")[key].meta);
354
+ return Promise.resolve(this.__internal__providers[key].meta);
359
355
  }
360
356
  rpcSubscribe({ method, params, type }, cb, port) {
361
- const provider = __classPrivateFieldGet(this, _State_injectedProviders, "f").get(port);
357
+ const provider = this.__internal__injectedProviders.get(port);
362
358
  assert(provider, 'Cannot call pub(rpc.subscribe) before provider is set');
363
359
  return provider.subscribe(type, method, params, cb);
364
360
  }
365
361
  rpcSubscribeConnected(_request, cb, port) {
366
- const provider = __classPrivateFieldGet(this, _State_injectedProviders, "f").get(port);
362
+ const provider = this.__internal__injectedProviders.get(port);
367
363
  assert(provider, 'Cannot call pub(rpc.subscribeConnected) before provider is set');
368
364
  cb(null, provider.isConnected); // Immediately send back current isConnected
369
365
  provider.on('connected', () => cb(null, true));
370
366
  provider.on('disconnected', () => cb(null, false));
371
367
  }
372
368
  rpcUnsubscribe(request, port) {
373
- const provider = __classPrivateFieldGet(this, _State_injectedProviders, "f").get(port);
369
+ const provider = this.__internal__injectedProviders.get(port);
374
370
  assert(provider, 'Cannot call pub(rpc.unsubscribe) before provider is set');
375
371
  return provider.unsubscribe(request.type, request.method, request.subscriptionId);
376
372
  }
377
373
  saveMetadata(meta) {
378
- __classPrivateFieldGet(this, _State_metaStore, "f").set(meta.genesisHash, meta);
374
+ this.__internal__metaStore.set(meta.genesisHash, meta);
379
375
  addMetadata(meta);
380
376
  }
381
377
  setNotification(notification) {
382
- __classPrivateFieldSet(this, _State_notification, notification, "f");
378
+ this.__internal__notification = notification;
383
379
  return true;
384
380
  }
385
381
  sign(url, request, account) {
386
382
  const id = getId();
387
383
  return new Promise((resolve, reject) => {
388
- __classPrivateFieldGet(this, _State_signRequests, "f")[id] = {
384
+ this.__internal__signRequests[id] = {
389
385
  ...this.signComplete(id, resolve, reject),
390
386
  account,
391
387
  id,
@@ -397,4 +393,3 @@ export default class State {
397
393
  });
398
394
  }
399
395
  }
400
- _State_authUrls = new WeakMap(), _State_authRequests = new WeakMap(), _State_metaStore = new WeakMap(), _State_injectedProviders = new WeakMap(), _State_metaRequests = new WeakMap(), _State_notification = new WeakMap(), _State_providers = new WeakMap(), _State_signRequests = new WeakMap(), _State_windows = new WeakMap(), _State_connectedTabsUrl = new WeakMap();
@@ -1,6 +1,6 @@
1
1
  /// <reference types="chrome" />
2
2
  import type { MessageTypes, RequestTypes, ResponseTypes } from '../types.js';
3
- import State from './State.js';
3
+ import type State from './State.js';
4
4
  export default class Tabs {
5
5
  #private;
6
6
  constructor(state: State);