@polkadot/extension-base 0.49.3 → 0.50.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.
@@ -293,11 +293,11 @@ export default class Extension {
293
293
  });
294
294
  return true;
295
295
  }
296
- signingApproveSignature({ id, signature }) {
296
+ signingApproveSignature({ id, signature, signedTransaction }) {
297
297
  const queued = this.__internal__state.getSignRequest(id);
298
298
  assert(queued, 'Unable to find request');
299
299
  const { resolve } = queued;
300
- resolve({ id, signature });
300
+ resolve({ id, signature, signedTransaction });
301
301
  return true;
302
302
  }
303
303
  signingCancel({ id }) {
@@ -378,7 +378,7 @@ export default class Extension {
378
378
  return this.__internal__state.deleteAuthRequest(requestId);
379
379
  }
380
380
  updateCurrentTabs({ urls }) {
381
- this.__internal__state.udateCurrentTabsUrl(urls);
381
+ this.__internal__state.updateCurrentTabsUrl(urls);
382
382
  }
383
383
  getConnectedTabsUrl() {
384
384
  return this.__internal__state.getConnectedTabsUrl();
@@ -43,6 +43,7 @@ export default class State {
43
43
  readonly authSubject: BehaviorSubject<AuthorizeRequest[]>;
44
44
  readonly metaSubject: BehaviorSubject<MetadataRequest[]>;
45
45
  readonly signSubject: BehaviorSubject<SigningRequest[]>;
46
+ readonly authUrlSubjects: Record<string, BehaviorSubject<AuthUrlInfo>>;
46
47
  defaultAuthAccountSelection: string[];
47
48
  constructor(providers?: Providers);
48
49
  init(): Promise<void>;
@@ -54,11 +55,14 @@ export default class State {
54
55
  get allMetaRequests(): MetadataRequest[];
55
56
  get allSignRequests(): SigningRequest[];
56
57
  get authUrls(): AuthUrls;
57
- private set authUrls(value);
58
58
  private popupClose;
59
59
  private popupOpen;
60
60
  private authComplete;
61
+ /**
62
+ * @deprecated This method is deprecated in favor of {@link updateCurrentTabs} and will be removed in a future release.
63
+ */
61
64
  udateCurrentTabsUrl(urls: string[]): void;
65
+ updateCurrentTabsUrl(urls: string[]): void;
62
66
  getConnectedTabsUrl(): string[];
63
67
  deleteAuthRequest(requestId: string): void;
64
68
  private saveCurrentAuthList;
@@ -72,7 +76,7 @@ export default class State {
72
76
  private updateIconAuth;
73
77
  private updateIconMeta;
74
78
  private updateIconSign;
75
- updateAuthorizedAccounts(authorizedAccountDiff: AuthorizedAccountsDiff): Promise<void>;
79
+ updateAuthorizedAccounts(authorizedAccountsDiff: AuthorizedAccountsDiff): Promise<void>;
76
80
  authorizeUrl(url: string, request: RequestAuthorizeTab): Promise<AuthResponse>;
77
81
  ensureUrlAuthorized(url: string): boolean;
78
82
  injectMetadata(url: string, request: MetadataDef): Promise<boolean>;
@@ -78,6 +78,7 @@ export default class State {
78
78
  authSubject = new BehaviorSubject([]);
79
79
  metaSubject = new BehaviorSubject([]);
80
80
  signSubject = new BehaviorSubject([]);
81
+ authUrlSubjects = {};
81
82
  defaultAuthAccountSelection = [];
82
83
  constructor(providers = {}) {
83
84
  this.__internal__providers = providers;
@@ -89,6 +90,10 @@ export default class State {
89
90
  const authString = storageAuthUrls?.[AUTH_URLS_KEY] || '{}';
90
91
  const previousAuth = JSON.parse(authString);
91
92
  this.__internal__authUrls = previousAuth;
93
+ // Initialize authUrlSubjects for each URL
94
+ Object.entries(previousAuth).forEach(([url, authInfo]) => {
95
+ this.authUrlSubjects[url] = new BehaviorSubject(authInfo);
96
+ });
92
97
  // retrieve previously set default auth accounts
93
98
  const storageDefaultAuthAccounts = await chrome.storage.local.get(DEFAULT_AUTH_ACCOUNTS);
94
99
  const defaultAuthString = storageDefaultAuthAccounts?.[DEFAULT_AUTH_ACCOUNTS] || '[]';
@@ -125,9 +130,6 @@ export default class State {
125
130
  get authUrls() {
126
131
  return this.__internal__authUrls;
127
132
  }
128
- set authUrls(urls) {
129
- this.__internal__authUrls = urls;
130
- }
131
133
  popupClose() {
132
134
  this.__internal__windows.forEach((id) => withErrorLog(() => chrome.windows.remove(id)));
133
135
  this.__internal__windows = [];
@@ -145,13 +147,21 @@ export default class State {
145
147
  authComplete = (id, resolve, reject) => {
146
148
  const complete = async (authorizedAccounts = []) => {
147
149
  const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
148
- this.__internal__authUrls[this.stripUrl(url)] = {
150
+ const strippedUrl = this.stripUrl(url);
151
+ const authInfo = {
149
152
  authorizedAccounts,
150
153
  count: 0,
151
154
  id: idStr,
152
155
  origin,
153
156
  url
154
157
  };
158
+ this.__internal__authUrls[strippedUrl] = authInfo;
159
+ if (!this.authUrlSubjects[strippedUrl]) {
160
+ this.authUrlSubjects[strippedUrl] = new BehaviorSubject(authInfo);
161
+ }
162
+ else {
163
+ this.authUrlSubjects[strippedUrl].next(authInfo);
164
+ }
155
165
  await this.saveCurrentAuthList();
156
166
  await this.updateDefaultAuthAccounts(authorizedAccounts);
157
167
  delete this.__internal__authRequests[id];
@@ -170,7 +180,13 @@ export default class State {
170
180
  }
171
181
  };
172
182
  };
183
+ /**
184
+ * @deprecated This method is deprecated in favor of {@link updateCurrentTabs} and will be removed in a future release.
185
+ */
173
186
  udateCurrentTabsUrl(urls) {
187
+ this.updateCurrentTabsUrl(urls);
188
+ }
189
+ updateCurrentTabsUrl(urls) {
174
190
  const connectedTabs = urls.map((url) => {
175
191
  let strippedUrl = '';
176
192
  // the assert in stripUrl may throw for new tabs with "chrome://newtab/"
@@ -261,6 +277,10 @@ export default class State {
261
277
  assert(entry, `The source ${url} is not known`);
262
278
  delete this.__internal__authUrls[url];
263
279
  await this.saveCurrentAuthList();
280
+ if (this.authUrlSubjects[url]) {
281
+ entry.authorizedAccounts = [];
282
+ this.authUrlSubjects[url].next(entry);
283
+ }
264
284
  return this.__internal__authUrls;
265
285
  }
266
286
  updateIconAuth(shouldClose) {
@@ -275,9 +295,10 @@ export default class State {
275
295
  this.signSubject.next(this.allSignRequests);
276
296
  this.updateIcon(shouldClose);
277
297
  }
278
- async updateAuthorizedAccounts(authorizedAccountDiff) {
279
- authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
298
+ async updateAuthorizedAccounts(authorizedAccountsDiff) {
299
+ authorizedAccountsDiff.forEach(([url, authorizedAccountDiff]) => {
280
300
  this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
301
+ this.authUrlSubjects[url].next(this.__internal__authUrls[url]);
281
302
  });
282
303
  await this.saveCurrentAuthList();
283
304
  }
@@ -1,3 +1,4 @@
1
+ import { combineLatest } from 'rxjs';
1
2
  import { checkIfDenied } from '@polkadot/phishing';
2
3
  import { keyring } from '@polkadot/ui-keyring';
3
4
  import { accounts as accountsObservable } from '@polkadot/ui-keyring/observable/accounts';
@@ -29,6 +30,9 @@ export default class Tabs {
29
30
  }
30
31
  filterForAuthorizedAccounts(accounts, url) {
31
32
  const auth = this.__internal__state.authUrls[this.__internal__state.stripUrl(url)];
33
+ if (!auth) {
34
+ return [];
35
+ }
32
36
  return accounts.filter((allAcc) => auth.authorizedAccounts
33
37
  // we have a list, use it
34
38
  ? auth.authorizedAccounts.includes(allAcc.address)
@@ -44,8 +48,14 @@ export default class Tabs {
44
48
  }
45
49
  accountsSubscribeAuthorized(url, id, port) {
46
50
  const cb = createSubscription(id, port);
51
+ const strippedUrl = this.__internal__state.stripUrl(url);
52
+ const authUrlObservable = this.__internal__state.authUrlSubjects[strippedUrl]?.asObservable();
53
+ if (!authUrlObservable) {
54
+ console.error(`No authUrlSubject found for ${strippedUrl}`);
55
+ return id;
56
+ }
47
57
  this.__internal__accountSubs[id] = {
48
- subscription: accountsObservable.subject.subscribe((accounts) => {
58
+ subscription: combineLatest([accountsObservable.subject, authUrlObservable]).subscribe(([accounts, _authUrlInfo]) => {
49
59
  const transformedAccounts = transformAccounts(accounts);
50
60
  cb(this.filterForAuthorizedAccounts(transformedAccounts, url));
51
61
  }),
@@ -244,6 +244,7 @@ export interface RequestSigningApprovePassword {
244
244
  export interface RequestSigningApproveSignature {
245
245
  id: string;
246
246
  signature: HexString;
247
+ signedTransaction?: HexString;
247
248
  }
248
249
  export interface RequestSigningCancel {
249
250
  id: string;
@@ -284,6 +285,7 @@ export type TransportResponseMessage<TMessageType extends MessageTypes> = TMessa
284
285
  export interface ResponseSigning {
285
286
  id: string;
286
287
  signature: HexString;
288
+ signedTransaction?: HexString;
287
289
  }
288
290
  export interface ResponseDeriveValidate {
289
291
  address: string;
@@ -295,11 +295,11 @@ class Extension {
295
295
  });
296
296
  return true;
297
297
  }
298
- signingApproveSignature({ id, signature }) {
298
+ signingApproveSignature({ id, signature, signedTransaction }) {
299
299
  const queued = this.__internal__state.getSignRequest(id);
300
300
  (0, util_1.assert)(queued, 'Unable to find request');
301
301
  const { resolve } = queued;
302
- resolve({ id, signature });
302
+ resolve({ id, signature, signedTransaction });
303
303
  return true;
304
304
  }
305
305
  signingCancel({ id }) {
@@ -380,7 +380,7 @@ class Extension {
380
380
  return this.__internal__state.deleteAuthRequest(requestId);
381
381
  }
382
382
  updateCurrentTabs({ urls }) {
383
- this.__internal__state.udateCurrentTabsUrl(urls);
383
+ this.__internal__state.updateCurrentTabsUrl(urls);
384
384
  }
385
385
  getConnectedTabsUrl() {
386
386
  return this.__internal__state.getConnectedTabsUrl();
@@ -81,6 +81,7 @@ class State {
81
81
  authSubject = new rxjs_1.BehaviorSubject([]);
82
82
  metaSubject = new rxjs_1.BehaviorSubject([]);
83
83
  signSubject = new rxjs_1.BehaviorSubject([]);
84
+ authUrlSubjects = {};
84
85
  defaultAuthAccountSelection = [];
85
86
  constructor(providers = {}) {
86
87
  this.__internal__providers = providers;
@@ -92,6 +93,10 @@ class State {
92
93
  const authString = storageAuthUrls?.[AUTH_URLS_KEY] || '{}';
93
94
  const previousAuth = JSON.parse(authString);
94
95
  this.__internal__authUrls = previousAuth;
96
+ // Initialize authUrlSubjects for each URL
97
+ Object.entries(previousAuth).forEach(([url, authInfo]) => {
98
+ this.authUrlSubjects[url] = new rxjs_1.BehaviorSubject(authInfo);
99
+ });
95
100
  // retrieve previously set default auth accounts
96
101
  const storageDefaultAuthAccounts = await chrome.storage.local.get(DEFAULT_AUTH_ACCOUNTS);
97
102
  const defaultAuthString = storageDefaultAuthAccounts?.[DEFAULT_AUTH_ACCOUNTS] || '[]';
@@ -128,9 +133,6 @@ class State {
128
133
  get authUrls() {
129
134
  return this.__internal__authUrls;
130
135
  }
131
- set authUrls(urls) {
132
- this.__internal__authUrls = urls;
133
- }
134
136
  popupClose() {
135
137
  this.__internal__windows.forEach((id) => (0, helpers_js_1.withErrorLog)(() => chrome.windows.remove(id)));
136
138
  this.__internal__windows = [];
@@ -148,13 +150,21 @@ class State {
148
150
  authComplete = (id, resolve, reject) => {
149
151
  const complete = async (authorizedAccounts = []) => {
150
152
  const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
151
- this.__internal__authUrls[this.stripUrl(url)] = {
153
+ const strippedUrl = this.stripUrl(url);
154
+ const authInfo = {
152
155
  authorizedAccounts,
153
156
  count: 0,
154
157
  id: idStr,
155
158
  origin,
156
159
  url
157
160
  };
161
+ this.__internal__authUrls[strippedUrl] = authInfo;
162
+ if (!this.authUrlSubjects[strippedUrl]) {
163
+ this.authUrlSubjects[strippedUrl] = new rxjs_1.BehaviorSubject(authInfo);
164
+ }
165
+ else {
166
+ this.authUrlSubjects[strippedUrl].next(authInfo);
167
+ }
158
168
  await this.saveCurrentAuthList();
159
169
  await this.updateDefaultAuthAccounts(authorizedAccounts);
160
170
  delete this.__internal__authRequests[id];
@@ -173,7 +183,13 @@ class State {
173
183
  }
174
184
  };
175
185
  };
186
+ /**
187
+ * @deprecated This method is deprecated in favor of {@link updateCurrentTabs} and will be removed in a future release.
188
+ */
176
189
  udateCurrentTabsUrl(urls) {
190
+ this.updateCurrentTabsUrl(urls);
191
+ }
192
+ updateCurrentTabsUrl(urls) {
177
193
  const connectedTabs = urls.map((url) => {
178
194
  let strippedUrl = '';
179
195
  // the assert in stripUrl may throw for new tabs with "chrome://newtab/"
@@ -264,6 +280,10 @@ class State {
264
280
  (0, util_1.assert)(entry, `The source ${url} is not known`);
265
281
  delete this.__internal__authUrls[url];
266
282
  await this.saveCurrentAuthList();
283
+ if (this.authUrlSubjects[url]) {
284
+ entry.authorizedAccounts = [];
285
+ this.authUrlSubjects[url].next(entry);
286
+ }
267
287
  return this.__internal__authUrls;
268
288
  }
269
289
  updateIconAuth(shouldClose) {
@@ -278,9 +298,10 @@ class State {
278
298
  this.signSubject.next(this.allSignRequests);
279
299
  this.updateIcon(shouldClose);
280
300
  }
281
- async updateAuthorizedAccounts(authorizedAccountDiff) {
282
- authorizedAccountDiff.forEach(([url, authorizedAccountDiff]) => {
301
+ async updateAuthorizedAccounts(authorizedAccountsDiff) {
302
+ authorizedAccountsDiff.forEach(([url, authorizedAccountDiff]) => {
283
303
  this.__internal__authUrls[url].authorizedAccounts = authorizedAccountDiff;
304
+ this.authUrlSubjects[url].next(this.__internal__authUrls[url]);
284
305
  });
285
306
  await this.saveCurrentAuthList();
286
307
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
+ const rxjs_1 = require("rxjs");
4
5
  const phishing_1 = require("@polkadot/phishing");
5
6
  const ui_keyring_1 = require("@polkadot/ui-keyring");
6
7
  const accounts_1 = require("@polkadot/ui-keyring/observable/accounts");
@@ -32,6 +33,9 @@ class Tabs {
32
33
  }
33
34
  filterForAuthorizedAccounts(accounts, url) {
34
35
  const auth = this.__internal__state.authUrls[this.__internal__state.stripUrl(url)];
36
+ if (!auth) {
37
+ return [];
38
+ }
35
39
  return accounts.filter((allAcc) => auth.authorizedAccounts
36
40
  // we have a list, use it
37
41
  ? auth.authorizedAccounts.includes(allAcc.address)
@@ -47,8 +51,14 @@ class Tabs {
47
51
  }
48
52
  accountsSubscribeAuthorized(url, id, port) {
49
53
  const cb = (0, subscriptions_js_1.createSubscription)(id, port);
54
+ const strippedUrl = this.__internal__state.stripUrl(url);
55
+ const authUrlObservable = this.__internal__state.authUrlSubjects[strippedUrl]?.asObservable();
56
+ if (!authUrlObservable) {
57
+ console.error(`No authUrlSubject found for ${strippedUrl}`);
58
+ return id;
59
+ }
50
60
  this.__internal__accountSubs[id] = {
51
- subscription: accounts_1.accounts.subject.subscribe((accounts) => {
61
+ subscription: (0, rxjs_1.combineLatest)([accounts_1.accounts.subject, authUrlObservable]).subscribe(([accounts, _authUrlInfo]) => {
52
62
  const transformedAccounts = transformAccounts(accounts);
53
63
  cb(this.filterForAuthorizedAccounts(transformedAccounts, url));
54
64
  }),
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.packageInfo = void 0;
4
- exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.49.3' };
4
+ exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.50.1' };
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "./cjs/packageDetect.js"
19
19
  ],
20
20
  "type": "module",
21
- "version": "0.49.3",
21
+ "version": "0.50.1",
22
22
  "main": "./cjs/index.js",
23
23
  "module": "./index.js",
24
24
  "types": "./index.d.ts",
@@ -218,16 +218,16 @@
218
218
  },
219
219
  "dependencies": {
220
220
  "@polkadot/api": "^12.2.1",
221
- "@polkadot/extension-chains": "0.49.3",
222
- "@polkadot/extension-dapp": "0.49.3",
223
- "@polkadot/extension-inject": "0.49.3",
221
+ "@polkadot/extension-chains": "0.50.1",
222
+ "@polkadot/extension-dapp": "0.50.1",
223
+ "@polkadot/extension-inject": "0.50.1",
224
224
  "@polkadot/keyring": "^13.0.2",
225
225
  "@polkadot/networks": "^13.0.2",
226
226
  "@polkadot/phishing": "^0.23.1",
227
227
  "@polkadot/rpc-provider": "^12.2.1",
228
228
  "@polkadot/types": "^12.2.1",
229
- "@polkadot/ui-keyring": "^3.7.1",
230
- "@polkadot/ui-settings": "^3.7.1",
229
+ "@polkadot/ui-keyring": "^3.8.2",
230
+ "@polkadot/ui-settings": "^3.8.2",
231
231
  "@polkadot/util": "^13.0.2",
232
232
  "@polkadot/util-crypto": "^13.0.2",
233
233
  "eventemitter3": "^5.0.1",
package/packageInfo.js CHANGED
@@ -1 +1 @@
1
- export const packageInfo = { name: '@polkadot/extension-base', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.49.3' };
1
+ export const packageInfo = { name: '@polkadot/extension-base', path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto', type: 'esm', version: '0.50.1' };