@polkadot/extension-base 0.46.4 → 0.46.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/RequestBytesSign.js +3 -3
- package/background/RequestExtrinsicSign.js +1 -0
- package/background/handlers/Extension.js +2 -0
- package/background/handlers/State.js +74 -72
- package/background/handlers/Tabs.js +2 -1
- package/background/handlers/index.js +4 -1
- package/background/types.d.ts +9 -19
- package/cjs/background/RequestBytesSign.js +2 -2
- package/cjs/background/RequestExtrinsicSign.js +1 -0
- package/cjs/background/handlers/Extension.js +2 -0
- package/cjs/background/handlers/State.js +75 -73
- package/cjs/background/handlers/Tabs.js +2 -1
- package/cjs/background/handlers/index.js +4 -1
- package/cjs/defaults.js +3 -3
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/Injected.js +4 -0
- package/cjs/page/PostMessageProvider.js +9 -8
- package/cjs/stores/Base.js +1 -0
- package/defaults.js +3 -3
- package/package.json +16 -16
- package/packageInfo.js +1 -1
- package/page/Injected.js +4 -0
- package/page/PostMessageProvider.js +9 -8
- package/stores/Base.js +1 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { u8aToHex } from '@polkadot/util';
|
|
1
|
+
import { u8aToHex, u8aWrapBytes } from '@polkadot/util';
|
|
3
2
|
export default class RequestBytesSign {
|
|
3
|
+
payload;
|
|
4
4
|
constructor(payload) {
|
|
5
5
|
this.payload = payload;
|
|
6
6
|
}
|
|
7
7
|
sign(_registry, pair) {
|
|
8
8
|
return {
|
|
9
|
-
signature: u8aToHex(pair.sign(
|
|
9
|
+
signature: u8aToHex(pair.sign(u8aWrapBytes(this.payload.data)))
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -19,6 +19,8 @@ function isJsonPayload(value) {
|
|
|
19
19
|
return value.genesisHash !== undefined;
|
|
20
20
|
}
|
|
21
21
|
export default class Extension {
|
|
22
|
+
__internal__cachedUnlocks;
|
|
23
|
+
__internal__state;
|
|
22
24
|
constructor(state) {
|
|
23
25
|
this.__internal__cachedUnlocks = {};
|
|
24
26
|
this.__internal__state = state;
|
|
@@ -61,79 +61,23 @@ function extractMetadata(store) {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
export default class State {
|
|
64
|
+
__internal__authUrls = {};
|
|
65
|
+
__internal__authRequests = {};
|
|
66
|
+
__internal__metaStore = new MetadataStore();
|
|
67
|
+
// Map of providers currently injected in tabs
|
|
68
|
+
__internal__injectedProviders = new Map();
|
|
69
|
+
__internal__metaRequests = {};
|
|
70
|
+
__internal__notification = settings.notification;
|
|
71
|
+
// Map of all providers exposed by the extension, they are retrievable by key
|
|
72
|
+
__internal__providers;
|
|
73
|
+
__internal__signRequests = {};
|
|
74
|
+
__internal__windows = [];
|
|
75
|
+
__internal__connectedTabsUrl = [];
|
|
76
|
+
authSubject = new BehaviorSubject([]);
|
|
77
|
+
metaSubject = new BehaviorSubject([]);
|
|
78
|
+
signSubject = new BehaviorSubject([]);
|
|
79
|
+
defaultAuthAccountSelection = [];
|
|
64
80
|
constructor(providers = {}) {
|
|
65
|
-
this.__internal__authUrls = {};
|
|
66
|
-
this.__internal__authRequests = {};
|
|
67
|
-
this.__internal__metaStore = new MetadataStore();
|
|
68
|
-
// Map of providers currently injected in tabs
|
|
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 = [];
|
|
75
|
-
this.authSubject = new BehaviorSubject([]);
|
|
76
|
-
this.metaSubject = new BehaviorSubject([]);
|
|
77
|
-
this.signSubject = new BehaviorSubject([]);
|
|
78
|
-
this.defaultAuthAccountSelection = [];
|
|
79
|
-
this.authComplete = (id, resolve, reject) => {
|
|
80
|
-
const complete = (authorizedAccounts = []) => {
|
|
81
|
-
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
82
|
-
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
83
|
-
authorizedAccounts,
|
|
84
|
-
count: 0,
|
|
85
|
-
id: idStr,
|
|
86
|
-
origin,
|
|
87
|
-
url
|
|
88
|
-
};
|
|
89
|
-
this.saveCurrentAuthList();
|
|
90
|
-
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
91
|
-
delete this.__internal__authRequests[id];
|
|
92
|
-
this.updateIconAuth(true);
|
|
93
|
-
};
|
|
94
|
-
return {
|
|
95
|
-
reject: (error) => {
|
|
96
|
-
complete();
|
|
97
|
-
reject(error);
|
|
98
|
-
},
|
|
99
|
-
resolve: ({ authorizedAccounts, result }) => {
|
|
100
|
-
complete(authorizedAccounts);
|
|
101
|
-
resolve({ authorizedAccounts, result });
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
this.metaComplete = (id, resolve, reject) => {
|
|
106
|
-
const complete = () => {
|
|
107
|
-
delete this.__internal__metaRequests[id];
|
|
108
|
-
this.updateIconMeta(true);
|
|
109
|
-
};
|
|
110
|
-
return {
|
|
111
|
-
reject: (error) => {
|
|
112
|
-
complete();
|
|
113
|
-
reject(error);
|
|
114
|
-
},
|
|
115
|
-
resolve: (result) => {
|
|
116
|
-
complete();
|
|
117
|
-
resolve(result);
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
this.signComplete = (id, resolve, reject) => {
|
|
122
|
-
const complete = () => {
|
|
123
|
-
delete this.__internal__signRequests[id];
|
|
124
|
-
this.updateIconSign(true);
|
|
125
|
-
};
|
|
126
|
-
return {
|
|
127
|
-
reject: (error) => {
|
|
128
|
-
complete();
|
|
129
|
-
reject(error);
|
|
130
|
-
},
|
|
131
|
-
resolve: (result) => {
|
|
132
|
-
complete();
|
|
133
|
-
resolve(result);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
};
|
|
137
81
|
this.__internal__providers = providers;
|
|
138
82
|
extractMetadata(this.__internal__metaStore);
|
|
139
83
|
// retrieve previously set authorizations
|
|
@@ -189,6 +133,32 @@ export default class State {
|
|
|
189
133
|
}
|
|
190
134
|
});
|
|
191
135
|
}
|
|
136
|
+
authComplete = (id, resolve, reject) => {
|
|
137
|
+
const complete = (authorizedAccounts = []) => {
|
|
138
|
+
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
139
|
+
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
140
|
+
authorizedAccounts,
|
|
141
|
+
count: 0,
|
|
142
|
+
id: idStr,
|
|
143
|
+
origin,
|
|
144
|
+
url
|
|
145
|
+
};
|
|
146
|
+
this.saveCurrentAuthList();
|
|
147
|
+
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
148
|
+
delete this.__internal__authRequests[id];
|
|
149
|
+
this.updateIconAuth(true);
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
reject: (error) => {
|
|
153
|
+
complete();
|
|
154
|
+
reject(error);
|
|
155
|
+
},
|
|
156
|
+
resolve: ({ authorizedAccounts, result }) => {
|
|
157
|
+
complete(authorizedAccounts);
|
|
158
|
+
resolve({ authorizedAccounts, result });
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
};
|
|
192
162
|
udateCurrentTabsUrl(urls) {
|
|
193
163
|
const connectedTabs = urls.map((url) => {
|
|
194
164
|
let strippedUrl = '';
|
|
@@ -224,6 +194,38 @@ export default class State {
|
|
|
224
194
|
this.defaultAuthAccountSelection = newList;
|
|
225
195
|
this.saveDefaultAuthAccounts();
|
|
226
196
|
}
|
|
197
|
+
metaComplete = (id, resolve, reject) => {
|
|
198
|
+
const complete = () => {
|
|
199
|
+
delete this.__internal__metaRequests[id];
|
|
200
|
+
this.updateIconMeta(true);
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
reject: (error) => {
|
|
204
|
+
complete();
|
|
205
|
+
reject(error);
|
|
206
|
+
},
|
|
207
|
+
resolve: (result) => {
|
|
208
|
+
complete();
|
|
209
|
+
resolve(result);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
signComplete = (id, resolve, reject) => {
|
|
214
|
+
const complete = () => {
|
|
215
|
+
delete this.__internal__signRequests[id];
|
|
216
|
+
this.updateIconSign(true);
|
|
217
|
+
};
|
|
218
|
+
return {
|
|
219
|
+
reject: (error) => {
|
|
220
|
+
complete();
|
|
221
|
+
reject(error);
|
|
222
|
+
},
|
|
223
|
+
resolve: (result) => {
|
|
224
|
+
complete();
|
|
225
|
+
resolve(result);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
};
|
|
227
229
|
stripUrl(url) {
|
|
228
230
|
assert(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
229
231
|
const parts = url.split('/');
|
|
@@ -22,8 +22,9 @@ function transformAccounts(accounts, anyType = false) {
|
|
|
22
22
|
}));
|
|
23
23
|
}
|
|
24
24
|
export default class Tabs {
|
|
25
|
+
__internal__accountSubs = {};
|
|
26
|
+
__internal__state;
|
|
25
27
|
constructor(state) {
|
|
26
|
-
this.__internal__accountSubs = {};
|
|
27
28
|
this.__internal__state = state;
|
|
28
29
|
}
|
|
29
30
|
filterForAuthorizedAccounts(accounts, url) {
|
|
@@ -10,9 +10,12 @@ const tabs = new Tabs(state);
|
|
|
10
10
|
export default function handler({ id, message, request }, port, extensionPortName = PORT_EXTENSION) {
|
|
11
11
|
const isExtension = !port || port?.name === extensionPortName;
|
|
12
12
|
const sender = port?.sender;
|
|
13
|
+
if (!sender) {
|
|
14
|
+
throw new Error('Unable to extract message sender');
|
|
15
|
+
}
|
|
13
16
|
const from = isExtension
|
|
14
17
|
? 'extension'
|
|
15
|
-
: (sender.tab
|
|
18
|
+
: (sender.tab?.url) || sender.url || '<unknown>';
|
|
16
19
|
const source = `${from}: ${id}: ${message}`;
|
|
17
20
|
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
|
|
18
21
|
const promise = isExtension
|
package/background/types.d.ts
CHANGED
|
@@ -31,27 +31,17 @@ export interface AuthUrlInfo {
|
|
|
31
31
|
export type SeedLengths = 12 | 24;
|
|
32
32
|
export interface AccountJson extends KeyringPair$Meta {
|
|
33
33
|
address: string;
|
|
34
|
-
genesisHash?: string | null;
|
|
35
|
-
isExternal?: boolean;
|
|
36
|
-
isHardware?: boolean;
|
|
37
|
-
isHidden?: boolean;
|
|
38
|
-
isDefaultAuthSelected?: boolean;
|
|
39
|
-
name?: string;
|
|
40
|
-
parentAddress?: string;
|
|
41
|
-
suri?: string;
|
|
42
|
-
type?: KeypairType;
|
|
43
|
-
whenCreated?: number;
|
|
44
34
|
}
|
|
45
35
|
export type AccountWithChildren = AccountJson & {
|
|
46
36
|
children?: AccountWithChildren[];
|
|
47
37
|
};
|
|
48
|
-
export
|
|
38
|
+
export interface AccountsContext {
|
|
49
39
|
accounts: AccountJson[];
|
|
50
40
|
hierarchy: AccountWithChildren[];
|
|
51
41
|
master?: AccountJson;
|
|
52
42
|
selectedAccounts?: AccountJson['address'][];
|
|
53
43
|
setSelectedAccounts?: (address: AccountJson['address'][]) => void;
|
|
54
|
-
}
|
|
44
|
+
}
|
|
55
45
|
export interface AuthorizeRequest {
|
|
56
46
|
id: string;
|
|
57
47
|
request: RequestAuthorizeTab;
|
|
@@ -160,12 +150,12 @@ export interface RequestMetadataReject {
|
|
|
160
150
|
export type RequestMetadataSubscribe = null;
|
|
161
151
|
export interface RequestAccountCreateExternal {
|
|
162
152
|
address: string;
|
|
163
|
-
genesisHash?:
|
|
153
|
+
genesisHash?: HexString | null;
|
|
164
154
|
name: string;
|
|
165
155
|
}
|
|
166
156
|
export interface RequestAccountCreateSuri {
|
|
167
157
|
name: string;
|
|
168
|
-
genesisHash?:
|
|
158
|
+
genesisHash?: HexString | null;
|
|
169
159
|
password: string;
|
|
170
160
|
suri: string;
|
|
171
161
|
type?: KeypairType;
|
|
@@ -174,7 +164,7 @@ export interface RequestAccountCreateHardware {
|
|
|
174
164
|
accountIndex: number;
|
|
175
165
|
address: string;
|
|
176
166
|
addressOffset: number;
|
|
177
|
-
genesisHash:
|
|
167
|
+
genesisHash: HexString;
|
|
178
168
|
hardwareType: string;
|
|
179
169
|
name: string;
|
|
180
170
|
}
|
|
@@ -185,7 +175,7 @@ export interface RequestAccountChangePassword {
|
|
|
185
175
|
}
|
|
186
176
|
export interface RequestAccountEdit {
|
|
187
177
|
address: string;
|
|
188
|
-
genesisHash?:
|
|
178
|
+
genesisHash?: HexString | null;
|
|
189
179
|
name: string;
|
|
190
180
|
}
|
|
191
181
|
export interface RequestAccountForget {
|
|
@@ -197,7 +187,7 @@ export interface RequestAccountShow {
|
|
|
197
187
|
}
|
|
198
188
|
export interface RequestAccountTie {
|
|
199
189
|
address: string;
|
|
200
|
-
genesisHash:
|
|
190
|
+
genesisHash: HexString | null;
|
|
201
191
|
}
|
|
202
192
|
export interface RequestAccountValidate {
|
|
203
193
|
address: string;
|
|
@@ -205,7 +195,7 @@ export interface RequestAccountValidate {
|
|
|
205
195
|
}
|
|
206
196
|
export interface RequestDeriveCreate {
|
|
207
197
|
name: string;
|
|
208
|
-
genesisHash?:
|
|
198
|
+
genesisHash?: HexString | null;
|
|
209
199
|
suri: string;
|
|
210
200
|
parentAddress: string;
|
|
211
201
|
parentPassword: string;
|
|
@@ -340,7 +330,7 @@ export type AllowedPath = typeof ALLOWED_PATH[number];
|
|
|
340
330
|
export interface ResponseJsonGetAccountInfo {
|
|
341
331
|
address: string;
|
|
342
332
|
name: string;
|
|
343
|
-
genesisHash:
|
|
333
|
+
genesisHash: HexString;
|
|
344
334
|
type: KeypairType;
|
|
345
335
|
}
|
|
346
336
|
export interface ResponseAuthorizeList {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const wrapBytes_1 = require("@polkadot/extension-dapp/wrapBytes");
|
|
4
3
|
const util_1 = require("@polkadot/util");
|
|
5
4
|
class RequestBytesSign {
|
|
5
|
+
payload;
|
|
6
6
|
constructor(payload) {
|
|
7
7
|
this.payload = payload;
|
|
8
8
|
}
|
|
9
9
|
sign(_registry, pair) {
|
|
10
10
|
return {
|
|
11
|
-
signature: (0, util_1.u8aToHex)(pair.sign((0,
|
|
11
|
+
signature: (0, util_1.u8aToHex)(pair.sign((0, util_1.u8aWrapBytes)(this.payload.data)))
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -30,7 +30,7 @@ var NotificationOptions;
|
|
|
30
30
|
NotificationOptions[NotificationOptions["None"] = 0] = "None";
|
|
31
31
|
NotificationOptions[NotificationOptions["Normal"] = 1] = "Normal";
|
|
32
32
|
NotificationOptions[NotificationOptions["PopUp"] = 2] = "PopUp";
|
|
33
|
-
})(NotificationOptions
|
|
33
|
+
})(NotificationOptions || (exports.NotificationOptions = NotificationOptions = {}));
|
|
34
34
|
const AUTH_URLS_KEY = 'authUrls';
|
|
35
35
|
const DEFAULT_AUTH_ACCOUNTS = 'defaultAuthAccounts';
|
|
36
36
|
function extractMetadata(store) {
|
|
@@ -65,79 +65,23 @@ function extractMetadata(store) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
class State {
|
|
68
|
+
__internal__authUrls = {};
|
|
69
|
+
__internal__authRequests = {};
|
|
70
|
+
__internal__metaStore = new index_js_1.MetadataStore();
|
|
71
|
+
// Map of providers currently injected in tabs
|
|
72
|
+
__internal__injectedProviders = new Map();
|
|
73
|
+
__internal__metaRequests = {};
|
|
74
|
+
__internal__notification = ui_settings_1.default.notification;
|
|
75
|
+
// Map of all providers exposed by the extension, they are retrievable by key
|
|
76
|
+
__internal__providers;
|
|
77
|
+
__internal__signRequests = {};
|
|
78
|
+
__internal__windows = [];
|
|
79
|
+
__internal__connectedTabsUrl = [];
|
|
80
|
+
authSubject = new rxjs_1.BehaviorSubject([]);
|
|
81
|
+
metaSubject = new rxjs_1.BehaviorSubject([]);
|
|
82
|
+
signSubject = new rxjs_1.BehaviorSubject([]);
|
|
83
|
+
defaultAuthAccountSelection = [];
|
|
68
84
|
constructor(providers = {}) {
|
|
69
|
-
this.__internal__authUrls = {};
|
|
70
|
-
this.__internal__authRequests = {};
|
|
71
|
-
this.__internal__metaStore = new index_js_1.MetadataStore();
|
|
72
|
-
// Map of providers currently injected in tabs
|
|
73
|
-
this.__internal__injectedProviders = new Map();
|
|
74
|
-
this.__internal__metaRequests = {};
|
|
75
|
-
this.__internal__notification = ui_settings_1.default.notification;
|
|
76
|
-
this.__internal__signRequests = {};
|
|
77
|
-
this.__internal__windows = [];
|
|
78
|
-
this.__internal__connectedTabsUrl = [];
|
|
79
|
-
this.authSubject = new rxjs_1.BehaviorSubject([]);
|
|
80
|
-
this.metaSubject = new rxjs_1.BehaviorSubject([]);
|
|
81
|
-
this.signSubject = new rxjs_1.BehaviorSubject([]);
|
|
82
|
-
this.defaultAuthAccountSelection = [];
|
|
83
|
-
this.authComplete = (id, resolve, reject) => {
|
|
84
|
-
const complete = (authorizedAccounts = []) => {
|
|
85
|
-
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
86
|
-
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
87
|
-
authorizedAccounts,
|
|
88
|
-
count: 0,
|
|
89
|
-
id: idStr,
|
|
90
|
-
origin,
|
|
91
|
-
url
|
|
92
|
-
};
|
|
93
|
-
this.saveCurrentAuthList();
|
|
94
|
-
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
95
|
-
delete this.__internal__authRequests[id];
|
|
96
|
-
this.updateIconAuth(true);
|
|
97
|
-
};
|
|
98
|
-
return {
|
|
99
|
-
reject: (error) => {
|
|
100
|
-
complete();
|
|
101
|
-
reject(error);
|
|
102
|
-
},
|
|
103
|
-
resolve: ({ authorizedAccounts, result }) => {
|
|
104
|
-
complete(authorizedAccounts);
|
|
105
|
-
resolve({ authorizedAccounts, result });
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
this.metaComplete = (id, resolve, reject) => {
|
|
110
|
-
const complete = () => {
|
|
111
|
-
delete this.__internal__metaRequests[id];
|
|
112
|
-
this.updateIconMeta(true);
|
|
113
|
-
};
|
|
114
|
-
return {
|
|
115
|
-
reject: (error) => {
|
|
116
|
-
complete();
|
|
117
|
-
reject(error);
|
|
118
|
-
},
|
|
119
|
-
resolve: (result) => {
|
|
120
|
-
complete();
|
|
121
|
-
resolve(result);
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
this.signComplete = (id, resolve, reject) => {
|
|
126
|
-
const complete = () => {
|
|
127
|
-
delete this.__internal__signRequests[id];
|
|
128
|
-
this.updateIconSign(true);
|
|
129
|
-
};
|
|
130
|
-
return {
|
|
131
|
-
reject: (error) => {
|
|
132
|
-
complete();
|
|
133
|
-
reject(error);
|
|
134
|
-
},
|
|
135
|
-
resolve: (result) => {
|
|
136
|
-
complete();
|
|
137
|
-
resolve(result);
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
};
|
|
141
85
|
this.__internal__providers = providers;
|
|
142
86
|
extractMetadata(this.__internal__metaStore);
|
|
143
87
|
// retrieve previously set authorizations
|
|
@@ -193,6 +137,32 @@ class State {
|
|
|
193
137
|
}
|
|
194
138
|
});
|
|
195
139
|
}
|
|
140
|
+
authComplete = (id, resolve, reject) => {
|
|
141
|
+
const complete = (authorizedAccounts = []) => {
|
|
142
|
+
const { idStr, request: { origin }, url } = this.__internal__authRequests[id];
|
|
143
|
+
this.__internal__authUrls[this.stripUrl(url)] = {
|
|
144
|
+
authorizedAccounts,
|
|
145
|
+
count: 0,
|
|
146
|
+
id: idStr,
|
|
147
|
+
origin,
|
|
148
|
+
url
|
|
149
|
+
};
|
|
150
|
+
this.saveCurrentAuthList();
|
|
151
|
+
this.updateDefaultAuthAccounts(authorizedAccounts);
|
|
152
|
+
delete this.__internal__authRequests[id];
|
|
153
|
+
this.updateIconAuth(true);
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
reject: (error) => {
|
|
157
|
+
complete();
|
|
158
|
+
reject(error);
|
|
159
|
+
},
|
|
160
|
+
resolve: ({ authorizedAccounts, result }) => {
|
|
161
|
+
complete(authorizedAccounts);
|
|
162
|
+
resolve({ authorizedAccounts, result });
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
};
|
|
196
166
|
udateCurrentTabsUrl(urls) {
|
|
197
167
|
const connectedTabs = urls.map((url) => {
|
|
198
168
|
let strippedUrl = '';
|
|
@@ -228,6 +198,38 @@ class State {
|
|
|
228
198
|
this.defaultAuthAccountSelection = newList;
|
|
229
199
|
this.saveDefaultAuthAccounts();
|
|
230
200
|
}
|
|
201
|
+
metaComplete = (id, resolve, reject) => {
|
|
202
|
+
const complete = () => {
|
|
203
|
+
delete this.__internal__metaRequests[id];
|
|
204
|
+
this.updateIconMeta(true);
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
reject: (error) => {
|
|
208
|
+
complete();
|
|
209
|
+
reject(error);
|
|
210
|
+
},
|
|
211
|
+
resolve: (result) => {
|
|
212
|
+
complete();
|
|
213
|
+
resolve(result);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
signComplete = (id, resolve, reject) => {
|
|
218
|
+
const complete = () => {
|
|
219
|
+
delete this.__internal__signRequests[id];
|
|
220
|
+
this.updateIconSign(true);
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
reject: (error) => {
|
|
224
|
+
complete();
|
|
225
|
+
reject(error);
|
|
226
|
+
},
|
|
227
|
+
resolve: (result) => {
|
|
228
|
+
complete();
|
|
229
|
+
resolve(result);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
};
|
|
231
233
|
stripUrl(url) {
|
|
232
234
|
(0, util_1.assert)(url && (url.startsWith('http:') || url.startsWith('https:') || url.startsWith('ipfs:') || url.startsWith('ipns:')), `Invalid url ${url}, expected to start with http: or https: or ipfs: or ipns:`);
|
|
233
235
|
const parts = url.split('/');
|
|
@@ -25,8 +25,9 @@ function transformAccounts(accounts, anyType = false) {
|
|
|
25
25
|
}));
|
|
26
26
|
}
|
|
27
27
|
class Tabs {
|
|
28
|
+
__internal__accountSubs = {};
|
|
29
|
+
__internal__state;
|
|
28
30
|
constructor(state) {
|
|
29
|
-
this.__internal__accountSubs = {};
|
|
30
31
|
this.__internal__state = state;
|
|
31
32
|
}
|
|
32
33
|
filterForAuthorizedAccounts(accounts, url) {
|
|
@@ -15,9 +15,12 @@ const tabs = new Tabs_js_1.default(state);
|
|
|
15
15
|
function handler({ id, message, request }, port, extensionPortName = defaults_js_1.PORT_EXTENSION) {
|
|
16
16
|
const isExtension = !port || port?.name === extensionPortName;
|
|
17
17
|
const sender = port?.sender;
|
|
18
|
+
if (!sender) {
|
|
19
|
+
throw new Error('Unable to extract message sender');
|
|
20
|
+
}
|
|
18
21
|
const from = isExtension
|
|
19
22
|
? 'extension'
|
|
20
|
-
: (sender.tab
|
|
23
|
+
: (sender.tab?.url) || sender.url || '<unknown>';
|
|
21
24
|
const source = `${from}: ${id}: ${message}`;
|
|
22
25
|
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
|
|
23
26
|
const promise = isExtension
|
package/cjs/defaults.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PHISHING_PAGE_REDIRECT = exports.PASSWORD_EXPIRY_MS = exports.PASSWORD_EXPIRY_MIN = exports.ALLOWED_PATH = exports.MESSAGE_ORIGIN_CONTENT = exports.MESSAGE_ORIGIN_PAGE = exports.PORT_EXTENSION = exports.PORT_CONTENT = exports.EXTENSION_PREFIX = void 0;
|
|
4
|
-
exports.EXTENSION_PREFIX = process.env
|
|
5
|
-
if (!exports.EXTENSION_PREFIX && !process.env
|
|
4
|
+
exports.EXTENSION_PREFIX = process.env['EXTENSION_PREFIX'] || '';
|
|
5
|
+
if (!exports.EXTENSION_PREFIX && !process.env['PORT_PREFIX']) {
|
|
6
6
|
throw new Error('CRITICAL: The extension does not define an own EXTENSION_PREFIX environment variable as part of the build, this is required to ensure that messages are not shared between extensions. Failure to do so will yield messages sent to multiple extensions.');
|
|
7
7
|
}
|
|
8
|
-
const PORT_PREFIX = `${exports.EXTENSION_PREFIX || 'unknown'}-${process.env
|
|
8
|
+
const PORT_PREFIX = `${exports.EXTENSION_PREFIX || 'unknown'}-${process.env['PORT_PREFIX'] || 'unknown'}`;
|
|
9
9
|
exports.PORT_CONTENT = `${PORT_PREFIX}-content`;
|
|
10
10
|
exports.PORT_EXTENSION = `${PORT_PREFIX}-extension`;
|
|
11
11
|
exports.MESSAGE_ORIGIN_PAGE = `${PORT_PREFIX}-page`;
|
package/cjs/packageInfo.js
CHANGED
|
@@ -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.46.
|
|
4
|
+
exports.packageInfo = { name: '@polkadot/extension-base', path: typeof __dirname === 'string' ? __dirname : 'auto', type: 'cjs', version: '0.46.6' };
|
package/cjs/page/Injected.js
CHANGED
|
@@ -6,6 +6,10 @@ const Metadata_js_1 = tslib_1.__importDefault(require("./Metadata.js"));
|
|
|
6
6
|
const PostMessageProvider_js_1 = tslib_1.__importDefault(require("./PostMessageProvider.js"));
|
|
7
7
|
const Signer_js_1 = tslib_1.__importDefault(require("./Signer.js"));
|
|
8
8
|
class default_1 {
|
|
9
|
+
accounts;
|
|
10
|
+
metadata;
|
|
11
|
+
provider;
|
|
12
|
+
signer;
|
|
9
13
|
constructor(sendRequest) {
|
|
10
14
|
this.accounts = new Accounts_js_1.default(sendRequest);
|
|
11
15
|
this.metadata = new Metadata_js_1.default(sendRequest);
|
|
@@ -10,22 +10,23 @@ let sendRequest;
|
|
|
10
10
|
* @description Extension provider to be used by dapps
|
|
11
11
|
*/
|
|
12
12
|
class PostMessageProvider {
|
|
13
|
+
__internal__eventemitter;
|
|
14
|
+
// Whether or not the actual extension background provider is connected
|
|
15
|
+
__internal__isConnected = false;
|
|
16
|
+
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
17
|
+
// only unique for a given subscription method; which is why we identify
|
|
18
|
+
// the subscriptions based on subscription id + type
|
|
19
|
+
__internal__subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
13
20
|
/**
|
|
14
21
|
* @param {function} sendRequest The function to be called to send requests to the node
|
|
15
22
|
* @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
|
|
16
23
|
*/
|
|
17
24
|
constructor(_sendRequest) {
|
|
18
|
-
// Whether or not the actual extension background provider is connected
|
|
19
|
-
this.__internal__isConnected = false;
|
|
20
|
-
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
21
|
-
// only unique for a given subscription method; which is why we identify
|
|
22
|
-
// the subscriptions based on subscription id + type
|
|
23
|
-
this.__internal__subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
24
25
|
this.__internal__eventemitter = new eventemitter3_1.EventEmitter();
|
|
25
26
|
sendRequest = _sendRequest;
|
|
26
27
|
}
|
|
27
28
|
get isClonable() {
|
|
28
|
-
return true;
|
|
29
|
+
return !!true;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* @description Returns a clone of the object
|
|
@@ -54,7 +55,7 @@ class PostMessageProvider {
|
|
|
54
55
|
*/
|
|
55
56
|
get hasSubscriptions() {
|
|
56
57
|
// FIXME This should see if the extension's state's provider has subscriptions
|
|
57
|
-
return true;
|
|
58
|
+
return !!true;
|
|
58
59
|
}
|
|
59
60
|
/**
|
|
60
61
|
* @summary Whether the node is connected or not.
|
package/cjs/stores/Base.js
CHANGED
package/defaults.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const EXTENSION_PREFIX = process.env
|
|
2
|
-
if (!EXTENSION_PREFIX && !process.env
|
|
1
|
+
export const EXTENSION_PREFIX = process.env['EXTENSION_PREFIX'] || '';
|
|
2
|
+
if (!EXTENSION_PREFIX && !process.env['PORT_PREFIX']) {
|
|
3
3
|
throw new Error('CRITICAL: The extension does not define an own EXTENSION_PREFIX environment variable as part of the build, this is required to ensure that messages are not shared between extensions. Failure to do so will yield messages sent to multiple extensions.');
|
|
4
4
|
}
|
|
5
|
-
const PORT_PREFIX = `${EXTENSION_PREFIX || 'unknown'}-${process.env
|
|
5
|
+
const PORT_PREFIX = `${EXTENSION_PREFIX || 'unknown'}-${process.env['PORT_PREFIX'] || 'unknown'}`;
|
|
6
6
|
export const PORT_CONTENT = `${PORT_PREFIX}-content`;
|
|
7
7
|
export const PORT_EXTENSION = `${PORT_PREFIX}-extension`;
|
|
8
8
|
export const MESSAGE_ORIGIN_PAGE = `${PORT_PREFIX}-page`;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"bugs": "https://github.com/polkadot-js/extension/issues",
|
|
4
4
|
"description": "Functions, classes and other utilities used in @polkadot/extension",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=18"
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://github.com/polkadot-js/extension/tree/master/packages/extension-base#readme",
|
|
9
9
|
"license": "Apache-2.0",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"./cjs/detectPackage.js"
|
|
19
19
|
],
|
|
20
20
|
"type": "module",
|
|
21
|
-
"version": "0.46.
|
|
21
|
+
"version": "0.46.6",
|
|
22
22
|
"main": "./cjs/index.js",
|
|
23
23
|
"module": "./index.js",
|
|
24
24
|
"types": "./index.d.ts",
|
|
@@ -223,21 +223,21 @@
|
|
|
223
223
|
}
|
|
224
224
|
},
|
|
225
225
|
"dependencies": {
|
|
226
|
-
"@polkadot/api": "^10.
|
|
227
|
-
"@polkadot/extension-chains": "0.46.
|
|
228
|
-
"@polkadot/extension-dapp": "0.46.
|
|
229
|
-
"@polkadot/extension-inject": "0.46.
|
|
230
|
-
"@polkadot/keyring": "^12.
|
|
231
|
-
"@polkadot/networks": "^12.
|
|
232
|
-
"@polkadot/phishing": "^0.
|
|
233
|
-
"@polkadot/rpc-provider": "^10.
|
|
234
|
-
"@polkadot/types": "^10.
|
|
235
|
-
"@polkadot/ui-keyring": "^3.4
|
|
236
|
-
"@polkadot/ui-settings": "^3.4
|
|
237
|
-
"@polkadot/util": "^12.
|
|
238
|
-
"@polkadot/util-crypto": "^12.
|
|
226
|
+
"@polkadot/api": "^10.11.1",
|
|
227
|
+
"@polkadot/extension-chains": "0.46.6",
|
|
228
|
+
"@polkadot/extension-dapp": "0.46.6",
|
|
229
|
+
"@polkadot/extension-inject": "0.46.6",
|
|
230
|
+
"@polkadot/keyring": "^12.6.1",
|
|
231
|
+
"@polkadot/networks": "^12.6.1",
|
|
232
|
+
"@polkadot/phishing": "^0.22.1",
|
|
233
|
+
"@polkadot/rpc-provider": "^10.11.1",
|
|
234
|
+
"@polkadot/types": "^10.11.1",
|
|
235
|
+
"@polkadot/ui-keyring": "^3.6.4",
|
|
236
|
+
"@polkadot/ui-settings": "^3.6.4",
|
|
237
|
+
"@polkadot/util": "^12.6.1",
|
|
238
|
+
"@polkadot/util-crypto": "^12.6.1",
|
|
239
239
|
"eventemitter3": "^5.0.1",
|
|
240
240
|
"rxjs": "^7.8.1",
|
|
241
|
-
"tslib": "^2.
|
|
241
|
+
"tslib": "^2.6.2"
|
|
242
242
|
}
|
|
243
243
|
}
|
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.46.
|
|
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.46.6' };
|
package/page/Injected.js
CHANGED
|
@@ -3,6 +3,10 @@ import Metadata from './Metadata.js';
|
|
|
3
3
|
import PostMessageProvider from './PostMessageProvider.js';
|
|
4
4
|
import Signer from './Signer.js';
|
|
5
5
|
export default class {
|
|
6
|
+
accounts;
|
|
7
|
+
metadata;
|
|
8
|
+
provider;
|
|
9
|
+
signer;
|
|
6
10
|
constructor(sendRequest) {
|
|
7
11
|
this.accounts = new Accounts(sendRequest);
|
|
8
12
|
this.metadata = new Metadata(sendRequest);
|
|
@@ -8,22 +8,23 @@ let sendRequest;
|
|
|
8
8
|
* @description Extension provider to be used by dapps
|
|
9
9
|
*/
|
|
10
10
|
export default class PostMessageProvider {
|
|
11
|
+
__internal__eventemitter;
|
|
12
|
+
// Whether or not the actual extension background provider is connected
|
|
13
|
+
__internal__isConnected = false;
|
|
14
|
+
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
15
|
+
// only unique for a given subscription method; which is why we identify
|
|
16
|
+
// the subscriptions based on subscription id + type
|
|
17
|
+
__internal__subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
11
18
|
/**
|
|
12
19
|
* @param {function} sendRequest The function to be called to send requests to the node
|
|
13
20
|
* @param {function} subscriptionNotificationHandler Channel for receiving subscription messages
|
|
14
21
|
*/
|
|
15
22
|
constructor(_sendRequest) {
|
|
16
|
-
// Whether or not the actual extension background provider is connected
|
|
17
|
-
this.__internal__isConnected = false;
|
|
18
|
-
// Subscription IDs are (historically) not guaranteed to be globally unique;
|
|
19
|
-
// only unique for a given subscription method; which is why we identify
|
|
20
|
-
// the subscriptions based on subscription id + type
|
|
21
|
-
this.__internal__subscriptions = {}; // {[(type,subscriptionId)]: callback}
|
|
22
23
|
this.__internal__eventemitter = new EventEmitter();
|
|
23
24
|
sendRequest = _sendRequest;
|
|
24
25
|
}
|
|
25
26
|
get isClonable() {
|
|
26
|
-
return true;
|
|
27
|
+
return !!true;
|
|
27
28
|
}
|
|
28
29
|
/**
|
|
29
30
|
* @description Returns a clone of the object
|
|
@@ -52,7 +53,7 @@ export default class PostMessageProvider {
|
|
|
52
53
|
*/
|
|
53
54
|
get hasSubscriptions() {
|
|
54
55
|
// FIXME This should see if the extension's state's provider has subscriptions
|
|
55
|
-
return true;
|
|
56
|
+
return !!true;
|
|
56
57
|
}
|
|
57
58
|
/**
|
|
58
59
|
* @summary Whether the node is connected or not.
|