@subwallet/extension-base 0.3.6-0 → 0.3.6-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.
- package/{build/background → background}/KoniTypes.d.ts +0 -0
- package/{build/background → background}/KoniTypes.js +0 -0
- package/{build/background → background}/RequestBytesSign.d.ts +0 -0
- package/{build/background → background}/RequestBytesSign.js +0 -0
- package/{build/background → background}/RequestExtrinsicSign.d.ts +0 -0
- package/{build/background → background}/RequestExtrinsicSign.js +0 -0
- package/{build/background → background}/handlers/Extension.d.ts +0 -0
- package/{build/background → background}/handlers/Extension.js +0 -0
- package/{build/background → background}/handlers/State.d.ts +0 -0
- package/{build/background → background}/handlers/State.js +0 -0
- package/{build/background → background}/handlers/Tabs.d.ts +0 -0
- package/{build/background → background}/handlers/Tabs.js +0 -0
- package/{build/background → background}/handlers/helpers.d.ts +0 -0
- package/{build/background → background}/handlers/helpers.js +0 -0
- package/{build/background → background}/handlers/index.d.ts +0 -0
- package/{build/background → background}/handlers/index.js +0 -0
- package/{build/background → background}/handlers/subscriptions.d.ts +0 -0
- package/{build/background → background}/handlers/subscriptions.js +0 -0
- package/{build/background → background}/types.d.ts +0 -0
- package/{build/background → background}/types.js +0 -0
- package/{build/bundle.d.ts → bundle.d.ts} +0 -0
- package/{build/bundle.js → bundle.js} +0 -0
- package/{build-cjs → cjs}/background/KoniTypes.js +0 -0
- package/{build-cjs → cjs}/background/RequestBytesSign.js +0 -0
- package/{build-cjs → cjs}/background/RequestExtrinsicSign.js +0 -0
- package/{build-cjs → cjs}/background/handlers/Extension.js +0 -0
- package/{build-cjs → cjs}/background/handlers/State.js +0 -0
- package/{build-cjs → cjs}/background/handlers/Tabs.js +0 -0
- package/{build-cjs → cjs}/background/handlers/helpers.js +0 -0
- package/{build-cjs → cjs}/background/handlers/index.js +0 -0
- package/{build-cjs → cjs}/background/handlers/subscriptions.js +0 -0
- package/{build-cjs → cjs}/background/types.js +0 -0
- package/{build-cjs → cjs}/bundle.js +0 -0
- package/{build-cjs → cjs}/defaults.js +0 -0
- package/{build-cjs → cjs}/detectOther.js +0 -0
- package/{build-cjs → cjs}/detectPackage.js +0 -0
- package/{build-cjs → cjs}/index.js +0 -0
- package/{build/cjs → cjs}/package.json +0 -0
- package/{build-cjs → cjs}/packageInfo.js +0 -0
- package/{build-cjs → cjs}/page/Accounts.js +0 -0
- package/{build-cjs → cjs}/page/Injected.js +0 -0
- package/{build-cjs → cjs}/page/Metadata.js +0 -0
- package/{build-cjs → cjs}/page/PostMessageProvider.js +0 -0
- package/{build-cjs → cjs}/page/Signer.js +0 -0
- package/{build-cjs → cjs}/page/index.js +0 -0
- package/{build-cjs → cjs}/page/types.js +0 -0
- package/{build-cjs → cjs}/stores/Accounts.js +0 -0
- package/{build-cjs → cjs}/stores/Base.js +0 -0
- package/{build-cjs → cjs}/stores/Metadata.js +0 -0
- package/{build-cjs → cjs}/stores/index.js +0 -0
- package/{build-cjs → cjs}/types.js +0 -0
- package/{build-cjs → cjs}/utils/canDerive.js +0 -0
- package/{build-cjs → cjs}/utils/getId.js +0 -0
- package/{build-cjs → cjs}/utils/index.js +0 -0
- package/{build/defaults.d.ts → defaults.d.ts} +0 -0
- package/{build/defaults.js → defaults.js} +0 -0
- package/{build/detectOther.d.ts → detectOther.d.ts} +0 -0
- package/{build/detectOther.js → detectOther.js} +0 -0
- package/{build/detectPackage.d.ts → detectPackage.d.ts} +0 -0
- package/{build/detectPackage.js → detectPackage.js} +0 -0
- package/{build/index.d.ts → index.d.ts} +0 -0
- package/{build/index.js → index.js} +0 -0
- package/package.json +171 -7
- package/{build/packageInfo.d.ts → packageInfo.d.ts} +0 -0
- package/{build/packageInfo.js → packageInfo.js} +0 -0
- package/{build/page → page}/Accounts.d.ts +0 -0
- package/{build/page → page}/Accounts.js +0 -0
- package/{build/page → page}/Injected.d.ts +0 -0
- package/{build/page → page}/Injected.js +0 -0
- package/{build/page → page}/Metadata.d.ts +0 -0
- package/{build/page → page}/Metadata.js +0 -0
- package/{build/page → page}/PostMessageProvider.d.ts +0 -0
- package/{build/page → page}/PostMessageProvider.js +0 -0
- package/{build/page → page}/Signer.d.ts +0 -0
- package/{build/page → page}/Signer.js +0 -0
- package/{build/page → page}/index.d.ts +0 -0
- package/{build/page → page}/index.js +0 -0
- package/{build/page → page}/types.d.ts +0 -0
- package/{build/page → page}/types.js +0 -0
- package/{build/stores → stores}/Accounts.d.ts +0 -0
- package/{build/stores → stores}/Accounts.js +0 -0
- package/{build/stores → stores}/Base.d.ts +0 -0
- package/{build/stores → stores}/Base.js +0 -0
- package/{build/stores → stores}/Metadata.d.ts +0 -0
- package/{build/stores → stores}/Metadata.js +0 -0
- package/{build/stores → stores}/index.d.ts +0 -0
- package/{build/stores → stores}/index.js +0 -0
- package/{build/types.d.ts → types.d.ts} +0 -0
- package/{build/types.js → types.js} +0 -0
- package/{build/utils → utils}/canDerive.d.ts +0 -0
- package/{build/utils → utils}/canDerive.js +0 -0
- package/{build/utils → utils}/getId.d.ts +0 -0
- package/{build/utils → utils}/getId.js +0 -0
- package/{build/utils → utils}/index.d.ts +0 -0
- package/{build/utils → utils}/index.js +0 -0
- package/build/LICENSE +0 -201
- package/build/README.md +0 -10
- package/build/cjs/background/KoniTypes.js +0 -69
- package/build/cjs/background/RequestBytesSign.js +0 -27
- package/build/cjs/background/RequestExtrinsicSign.js +0 -23
- package/build/cjs/background/handlers/Extension.js +0 -764
- package/build/cjs/background/handlers/State.js +0 -472
- package/build/cjs/background/handlers/Tabs.js +0 -273
- package/build/cjs/background/handlers/helpers.js +0 -20
- package/build/cjs/background/handlers/index.js +0 -60
- package/build/cjs/background/handlers/subscriptions.js +0 -32
- package/build/cjs/background/types.js +0 -1
- package/build/cjs/bundle.js +0 -13
- package/build/cjs/defaults.js +0 -26
- package/build/cjs/detectOther.js +0 -17
- package/build/cjs/detectPackage.js +0 -14
- package/build/cjs/index.js +0 -18
- package/build/cjs/packageInfo.js +0 -16
- package/build/cjs/page/Accounts.js +0 -31
- package/build/cjs/page/Injected.js +0 -30
- package/build/cjs/page/Metadata.js +0 -27
- package/build/cjs/page/PostMessageProvider.js +0 -184
- package/build/cjs/page/Signer.js +0 -44
- package/build/cjs/page/index.js +0 -76
- package/build/cjs/page/types.js +0 -1
- package/build/cjs/stores/Accounts.js +0 -33
- package/build/cjs/stores/Base.js +0 -84
- package/build/cjs/stores/Metadata.js +0 -23
- package/build/cjs/stores/index.js +0 -23
- package/build/cjs/types.js +0 -1
- package/build/cjs/utils/canDerive.js +0 -12
- package/build/cjs/utils/getId.js +0 -16
- package/build/cjs/utils/index.js +0 -13
- package/build/package.json +0 -210
- package/src/background/KoniTypes.ts +0 -537
- package/src/background/RequestBytesSign.ts +0 -30
- package/src/background/RequestExtrinsicSign.ts +0 -23
- package/src/background/handlers/Extension.spec.ts +0 -456
- package/src/background/handlers/Extension.ts +0 -627
- package/src/background/handlers/State.ts +0 -513
- package/src/background/handlers/Tabs.ts +0 -223
- package/src/background/handlers/helpers.ts +0 -14
- package/src/background/handlers/index.ts +0 -49
- package/src/background/handlers/subscriptions.ts +0 -30
- package/src/background/types.ts +0 -437
- package/src/bundle.ts +0 -4
- package/src/defaults.ts +0 -24
- package/src/detectOther.ts +0 -8
- package/src/detectPackage.ts +0 -11
- package/src/index.ts +0 -7
- package/src/packageInfo.ts +0 -6
- package/src/page/Accounts.ts +0 -27
- package/src/page/Injected.ts +0 -27
- package/src/page/Metadata.ts +0 -22
- package/src/page/PostMessageProvider.ts +0 -178
- package/src/page/Signer.ts +0 -45
- package/src/page/index.ts +0 -87
- package/src/page/types.ts +0 -10
- package/src/stores/Accounts.ts +0 -24
- package/src/stores/Base.ts +0 -81
- package/src/stores/Metadata.ts +0 -13
- package/src/stores/index.ts +0 -5
- package/src/types.ts +0 -12
- package/src/utils/canDerive.ts +0 -8
- package/src/utils/getId.ts +0 -10
- package/src/utils/index.ts +0 -4
- package/tsconfig.build.json +0 -18
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.json +0 -14
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _defaults = require("@subwallet/extension-base/defaults");
|
|
11
|
-
|
|
12
|
-
var _utils = require("@subwallet/extension-base/utils");
|
|
13
|
-
|
|
14
|
-
var _phishing = require("@polkadot/phishing");
|
|
15
|
-
|
|
16
|
-
var _uiKeyring = _interopRequireDefault(require("@polkadot/ui-keyring"));
|
|
17
|
-
|
|
18
|
-
var _accounts = require("@polkadot/ui-keyring/observable/accounts");
|
|
19
|
-
|
|
20
|
-
var _util = require("@polkadot/util");
|
|
21
|
-
|
|
22
|
-
var _RequestBytesSign = _interopRequireDefault(require("../RequestBytesSign"));
|
|
23
|
-
|
|
24
|
-
var _RequestExtrinsicSign = _interopRequireDefault(require("../RequestExtrinsicSign"));
|
|
25
|
-
|
|
26
|
-
var _helpers = require("./helpers");
|
|
27
|
-
|
|
28
|
-
var _subscriptions = require("./subscriptions");
|
|
29
|
-
|
|
30
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
31
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
32
|
-
function transformAccounts(accounts) {
|
|
33
|
-
let anyType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
34
|
-
return Object.values(accounts).filter(_ref => {
|
|
35
|
-
let {
|
|
36
|
-
json: {
|
|
37
|
-
meta: {
|
|
38
|
-
isHidden
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
} = _ref;
|
|
42
|
-
return !isHidden;
|
|
43
|
-
}).filter(_ref2 => {
|
|
44
|
-
let {
|
|
45
|
-
type
|
|
46
|
-
} = _ref2;
|
|
47
|
-
return anyType ? true : (0, _utils.canDerive)(type);
|
|
48
|
-
}).filter(_ref3 => {
|
|
49
|
-
let {
|
|
50
|
-
type
|
|
51
|
-
} = _ref3;
|
|
52
|
-
return type !== 'ethereum';
|
|
53
|
-
}) // Quick fix DApp not allow EVM
|
|
54
|
-
.sort((a, b) => (a.json.meta.whenCreated || 0) - (b.json.meta.whenCreated || 0)).map(_ref4 => {
|
|
55
|
-
let {
|
|
56
|
-
json: {
|
|
57
|
-
address,
|
|
58
|
-
meta: {
|
|
59
|
-
genesisHash,
|
|
60
|
-
name
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
type
|
|
64
|
-
} = _ref4;
|
|
65
|
-
return {
|
|
66
|
-
address,
|
|
67
|
-
genesisHash,
|
|
68
|
-
name,
|
|
69
|
-
type
|
|
70
|
-
};
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
class Tabs {
|
|
75
|
-
#state;
|
|
76
|
-
|
|
77
|
-
constructor(state) {
|
|
78
|
-
this.#state = state;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
authorize(url, request) {
|
|
82
|
-
return this.#state.authorizeUrl(url, request);
|
|
83
|
-
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
accountsList(url, _ref5) {
|
|
87
|
-
let {
|
|
88
|
-
anyType
|
|
89
|
-
} = _ref5;
|
|
90
|
-
return transformAccounts(_accounts.accounts.subject.getValue(), anyType);
|
|
91
|
-
} // FIXME This looks very much like what we have in Extension
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
accountsSubscribe(url, id, port) {
|
|
95
|
-
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
96
|
-
|
|
97
|
-
const subscription = _accounts.accounts.subject.subscribe(accounts => cb(transformAccounts(accounts)));
|
|
98
|
-
|
|
99
|
-
port.onDisconnect.addListener(() => {
|
|
100
|
-
(0, _subscriptions.unsubscribe)(id);
|
|
101
|
-
subscription.unsubscribe();
|
|
102
|
-
});
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
getSigningPair(address) {
|
|
107
|
-
const pair = _uiKeyring.default.getPair(address);
|
|
108
|
-
|
|
109
|
-
(0, _util.assert)(pair, 'Unable to find keypair');
|
|
110
|
-
return pair;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
bytesSign(url, request) {
|
|
114
|
-
const address = request.address;
|
|
115
|
-
const pair = this.getSigningPair(address);
|
|
116
|
-
return this.#state.sign(url, new _RequestBytesSign.default(request), {
|
|
117
|
-
address,
|
|
118
|
-
...pair.meta
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
extrinsicSign(url, request) {
|
|
123
|
-
const address = request.address;
|
|
124
|
-
const pair = this.getSigningPair(address);
|
|
125
|
-
return this.#state.sign(url, new _RequestExtrinsicSign.default(request), {
|
|
126
|
-
address,
|
|
127
|
-
...pair.meta
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
metadataProvide(url, request) {
|
|
132
|
-
return this.#state.injectMetadata(url, request);
|
|
133
|
-
} // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
metadataList(url) {
|
|
137
|
-
return this.#state.knownMetadata.map(_ref6 => {
|
|
138
|
-
let {
|
|
139
|
-
genesisHash,
|
|
140
|
-
specVersion
|
|
141
|
-
} = _ref6;
|
|
142
|
-
return {
|
|
143
|
-
genesisHash,
|
|
144
|
-
specVersion
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
rpcListProviders() {
|
|
150
|
-
return this.#state.rpcListProviders();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
rpcSend(request, port) {
|
|
154
|
-
return this.#state.rpcSend(request, port);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
rpcStartProvider(key, port) {
|
|
158
|
-
return this.#state.rpcStartProvider(key, port);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async rpcSubscribe(request, id, port) {
|
|
162
|
-
const innerCb = (0, _subscriptions.createSubscription)(id, port);
|
|
163
|
-
|
|
164
|
-
const cb = (_error, data) => innerCb(data);
|
|
165
|
-
|
|
166
|
-
const subscriptionId = await this.#state.rpcSubscribe(request, cb, port);
|
|
167
|
-
port.onDisconnect.addListener(() => {
|
|
168
|
-
(0, _subscriptions.unsubscribe)(id);
|
|
169
|
-
(0, _helpers.withErrorLog)(() => this.rpcUnsubscribe({ ...request,
|
|
170
|
-
subscriptionId
|
|
171
|
-
}, port));
|
|
172
|
-
});
|
|
173
|
-
return true;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
rpcSubscribeConnected(request, id, port) {
|
|
177
|
-
const innerCb = (0, _subscriptions.createSubscription)(id, port);
|
|
178
|
-
|
|
179
|
-
const cb = (_error, data) => innerCb(data);
|
|
180
|
-
|
|
181
|
-
this.#state.rpcSubscribeConnected(request, cb, port);
|
|
182
|
-
port.onDisconnect.addListener(() => {
|
|
183
|
-
(0, _subscriptions.unsubscribe)(id);
|
|
184
|
-
});
|
|
185
|
-
return Promise.resolve(true);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async rpcUnsubscribe(request, port) {
|
|
189
|
-
return this.#state.rpcUnsubscribe(request, port);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
redirectPhishingLanding(phishingWebsite) {
|
|
193
|
-
const nonFragment = phishingWebsite.split('#')[0];
|
|
194
|
-
const encodedWebsite = encodeURIComponent(nonFragment);
|
|
195
|
-
const url = `${chrome.extension.getURL('index.html')}#${_defaults.PHISHING_PAGE_REDIRECT}/${encodedWebsite}`;
|
|
196
|
-
chrome.tabs.query({
|
|
197
|
-
url: nonFragment
|
|
198
|
-
}, tabs => {
|
|
199
|
-
tabs.map(_ref7 => {
|
|
200
|
-
let {
|
|
201
|
-
id
|
|
202
|
-
} = _ref7;
|
|
203
|
-
return id;
|
|
204
|
-
}).filter(id => (0, _util.isNumber)(id)).forEach(id => (0, _helpers.withErrorLog)(() => chrome.tabs.update(id, {
|
|
205
|
-
url
|
|
206
|
-
})));
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async redirectIfPhishing(url) {
|
|
211
|
-
const isInDenyList = await (0, _phishing.checkIfDenied)(url);
|
|
212
|
-
|
|
213
|
-
if (isInDenyList) {
|
|
214
|
-
this.redirectPhishingLanding(url);
|
|
215
|
-
return true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return false;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
async handle(id, type, request, url, port) {
|
|
222
|
-
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
223
|
-
return this.redirectIfPhishing(url);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
switch (type) {
|
|
227
|
-
case 'pub(authorize.tab)':
|
|
228
|
-
return this.authorize(url, request);
|
|
229
|
-
|
|
230
|
-
case 'pub(accounts.list)':
|
|
231
|
-
return this.accountsList(url, request);
|
|
232
|
-
|
|
233
|
-
case 'pub(accounts.subscribe)':
|
|
234
|
-
return this.accountsSubscribe(url, id, port);
|
|
235
|
-
|
|
236
|
-
case 'pub(bytes.sign)':
|
|
237
|
-
return this.bytesSign(url, request);
|
|
238
|
-
|
|
239
|
-
case 'pub(extrinsic.sign)':
|
|
240
|
-
return this.extrinsicSign(url, request);
|
|
241
|
-
|
|
242
|
-
case 'pub(metadata.list)':
|
|
243
|
-
return this.metadataList(url);
|
|
244
|
-
|
|
245
|
-
case 'pub(metadata.provide)':
|
|
246
|
-
return this.metadataProvide(url, request);
|
|
247
|
-
|
|
248
|
-
case 'pub(rpc.listProviders)':
|
|
249
|
-
return this.rpcListProviders();
|
|
250
|
-
|
|
251
|
-
case 'pub(rpc.send)':
|
|
252
|
-
return this.rpcSend(request, port);
|
|
253
|
-
|
|
254
|
-
case 'pub(rpc.startProvider)':
|
|
255
|
-
return this.rpcStartProvider(request, port);
|
|
256
|
-
|
|
257
|
-
case 'pub(rpc.subscribe)':
|
|
258
|
-
return this.rpcSubscribe(request, id, port);
|
|
259
|
-
|
|
260
|
-
case 'pub(rpc.subscribeConnected)':
|
|
261
|
-
return this.rpcSubscribeConnected(request, id, port);
|
|
262
|
-
|
|
263
|
-
case 'pub(rpc.unsubscribe)':
|
|
264
|
-
return this.rpcUnsubscribe(request, port);
|
|
265
|
-
|
|
266
|
-
default:
|
|
267
|
-
throw new Error(`Unable to handle message of type ${type}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
exports.default = Tabs;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.withErrorLog = withErrorLog;
|
|
7
|
-
|
|
8
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
9
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
-
function withErrorLog(fn) {
|
|
11
|
-
try {
|
|
12
|
-
const p = fn();
|
|
13
|
-
|
|
14
|
-
if (p && typeof p === 'object' && typeof p.catch === 'function') {
|
|
15
|
-
p.catch(console.error);
|
|
16
|
-
}
|
|
17
|
-
} catch (e) {
|
|
18
|
-
console.error(e);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = handler;
|
|
9
|
-
|
|
10
|
-
var _util = require("@polkadot/util");
|
|
11
|
-
|
|
12
|
-
var _defaults = require("../../defaults");
|
|
13
|
-
|
|
14
|
-
var _Extension = _interopRequireDefault(require("./Extension"));
|
|
15
|
-
|
|
16
|
-
var _State = _interopRequireDefault(require("./State"));
|
|
17
|
-
|
|
18
|
-
var _Tabs = _interopRequireDefault(require("./Tabs"));
|
|
19
|
-
|
|
20
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
21
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
22
|
-
const state = new _State.default();
|
|
23
|
-
const extension = new _Extension.default(state);
|
|
24
|
-
const tabs = new _Tabs.default(state);
|
|
25
|
-
|
|
26
|
-
function handler(_ref, port) {
|
|
27
|
-
let {
|
|
28
|
-
id,
|
|
29
|
-
message,
|
|
30
|
-
request
|
|
31
|
-
} = _ref;
|
|
32
|
-
let extensionPortName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _defaults.PORT_EXTENSION;
|
|
33
|
-
const isExtension = port.name === extensionPortName;
|
|
34
|
-
const sender = port.sender;
|
|
35
|
-
const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
|
|
36
|
-
const source = `${from}: ${id}: ${message}`;
|
|
37
|
-
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
|
|
38
|
-
|
|
39
|
-
const promise = isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
|
|
40
|
-
promise.then(response => {
|
|
41
|
-
console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
|
|
42
|
-
// between the start and the end of the promise, the user may have closed
|
|
43
|
-
// the tab, in which case port will be undefined
|
|
44
|
-
|
|
45
|
-
(0, _util.assert)(port, 'Port has been disconnected');
|
|
46
|
-
port.postMessage({
|
|
47
|
-
id,
|
|
48
|
-
response
|
|
49
|
-
});
|
|
50
|
-
}).catch(error => {
|
|
51
|
-
console.log(`[err] ${source}:: ${error.message}`); // only send message back to port if it's still connected
|
|
52
|
-
|
|
53
|
-
if (port) {
|
|
54
|
-
port.postMessage({
|
|
55
|
-
error: error.message,
|
|
56
|
-
id
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createSubscription = createSubscription;
|
|
7
|
-
exports.unsubscribe = unsubscribe;
|
|
8
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
9
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
-
const subscriptions = {}; // return a subscription callback, that will send the data to the caller via the port
|
|
11
|
-
|
|
12
|
-
function createSubscription(id, port) {
|
|
13
|
-
subscriptions[id] = port;
|
|
14
|
-
return subscription => {
|
|
15
|
-
if (subscriptions[id]) {
|
|
16
|
-
port.postMessage({
|
|
17
|
-
id,
|
|
18
|
-
subscription
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
} // clear a previous subscriber
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function unsubscribe(id) {
|
|
26
|
-
if (subscriptions[id]) {
|
|
27
|
-
console.log(`Unsubscribing from ${id}`);
|
|
28
|
-
delete subscriptions[id];
|
|
29
|
-
} else {
|
|
30
|
-
console.error(`Unable to unsubscribe from ${id}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/build/cjs/bundle.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "packageInfo", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _packageInfo.packageInfo;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
var _packageInfo = require("./packageInfo");
|
package/build/cjs/defaults.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.PORT_EXTENSION = exports.PORT_CONTENT = exports.PHISHING_PAGE_REDIRECT = exports.PASSWORD_EXPIRY_MS = exports.PASSWORD_EXPIRY_MIN = exports.MESSAGE_ORIGIN_PAGE = exports.MESSAGE_ORIGIN_CONTENT = exports.EXTENSION_PREFIX = exports.ALLOWED_PATH = void 0;
|
|
7
|
-
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
const ALLOWED_PATH = ['/', '/account/import-ledger', '/account/restore-json', '/account/create'];
|
|
10
|
-
exports.ALLOWED_PATH = ALLOWED_PATH;
|
|
11
|
-
const PHISHING_PAGE_REDIRECT = '/phishing-page-detected';
|
|
12
|
-
exports.PHISHING_PAGE_REDIRECT = PHISHING_PAGE_REDIRECT;
|
|
13
|
-
const EXTENSION_PREFIX = process.env.EXTENSION_PREFIX || '';
|
|
14
|
-
exports.EXTENSION_PREFIX = EXTENSION_PREFIX;
|
|
15
|
-
const PORT_CONTENT = `${EXTENSION_PREFIX}koni-content`;
|
|
16
|
-
exports.PORT_CONTENT = PORT_CONTENT;
|
|
17
|
-
const PORT_EXTENSION = `${EXTENSION_PREFIX}koni-extension`;
|
|
18
|
-
exports.PORT_EXTENSION = PORT_EXTENSION;
|
|
19
|
-
const MESSAGE_ORIGIN_PAGE = `${EXTENSION_PREFIX}koni-page`;
|
|
20
|
-
exports.MESSAGE_ORIGIN_PAGE = MESSAGE_ORIGIN_PAGE;
|
|
21
|
-
const MESSAGE_ORIGIN_CONTENT = `${EXTENSION_PREFIX}koni-content`;
|
|
22
|
-
exports.MESSAGE_ORIGIN_CONTENT = MESSAGE_ORIGIN_CONTENT;
|
|
23
|
-
const PASSWORD_EXPIRY_MIN = 15;
|
|
24
|
-
exports.PASSWORD_EXPIRY_MIN = PASSWORD_EXPIRY_MIN;
|
|
25
|
-
const PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MIN * 60 * 1000;
|
|
26
|
-
exports.PASSWORD_EXPIRY_MS = PASSWORD_EXPIRY_MS;
|
package/build/cjs/detectOther.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _packageInfo = require("@subwallet/extension-chains/cjs/packageInfo");
|
|
9
|
-
|
|
10
|
-
var _packageInfo2 = require("@subwallet/extension-dapp/cjs/packageInfo");
|
|
11
|
-
|
|
12
|
-
var _packageInfo3 = require("@subwallet/extension-inject/cjs/packageInfo");
|
|
13
|
-
|
|
14
|
-
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
15
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
-
var _default = [_packageInfo.packageInfo, _packageInfo2.packageInfo, _packageInfo3.packageInfo];
|
|
17
|
-
exports.default = _default;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _util = require("@polkadot/util");
|
|
6
|
-
|
|
7
|
-
var _detectOther = _interopRequireDefault(require("./detectOther"));
|
|
8
|
-
|
|
9
|
-
var _packageInfo = require("./packageInfo");
|
|
10
|
-
|
|
11
|
-
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
12
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
14
|
-
(0, _util.detectPackage)(_packageInfo.packageInfo, null, _detectOther.default);
|
package/build/cjs/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _bundle = require("./bundle");
|
|
8
|
-
|
|
9
|
-
Object.keys(_bundle).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _bundle[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _bundle[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
package/build/cjs/packageInfo.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.packageInfo = void 0;
|
|
7
|
-
// Copyright 2017-2022 @subwallet/extension-base authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
// Do not edit, auto-generated by @polkadot/dev
|
|
10
|
-
const packageInfo = {
|
|
11
|
-
name: '@subwallet/extension-base',
|
|
12
|
-
path: typeof __dirname === 'string' ? __dirname : 'auto',
|
|
13
|
-
type: 'cjs',
|
|
14
|
-
version: '0.3.6-0'
|
|
15
|
-
};
|
|
16
|
-
exports.packageInfo = packageInfo;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
// External to class, this.# is not private enough (yet)
|
|
10
|
-
let sendRequest;
|
|
11
|
-
|
|
12
|
-
class Accounts {
|
|
13
|
-
constructor(_sendRequest) {
|
|
14
|
-
sendRequest = _sendRequest;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get(anyType) {
|
|
18
|
-
return sendRequest('pub(accounts.listV2)', {
|
|
19
|
-
anyType
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
subscribe(cb) {
|
|
24
|
-
sendRequest('pub(accounts.subscribeV2)', null, cb).catch(error => console.error(error));
|
|
25
|
-
return () => {// FIXME we need the ability to unsubscribe
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.default = Accounts;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _Accounts = _interopRequireDefault(require("./Accounts"));
|
|
11
|
-
|
|
12
|
-
var _Metadata = _interopRequireDefault(require("./Metadata"));
|
|
13
|
-
|
|
14
|
-
var _PostMessageProvider = _interopRequireDefault(require("./PostMessageProvider"));
|
|
15
|
-
|
|
16
|
-
var _Signer = _interopRequireDefault(require("./Signer"));
|
|
17
|
-
|
|
18
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
19
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
-
class _default {
|
|
21
|
-
constructor(sendRequest) {
|
|
22
|
-
this.accounts = new _Accounts.default(sendRequest);
|
|
23
|
-
this.metadata = new _Metadata.default(sendRequest);
|
|
24
|
-
this.provider = new _PostMessageProvider.default(sendRequest);
|
|
25
|
-
this.signer = new _Signer.default(sendRequest);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
exports.default = _default;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
// Copyright 2019-2022 @subwallet/extension authors & contributors
|
|
8
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
9
|
-
// External to class, this.# is not private enough (yet)
|
|
10
|
-
let sendRequest;
|
|
11
|
-
|
|
12
|
-
class Metadata {
|
|
13
|
-
constructor(_sendRequest) {
|
|
14
|
-
sendRequest = _sendRequest;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get() {
|
|
18
|
-
return sendRequest('pub(metadata.list)');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
provide(definition) {
|
|
22
|
-
return sendRequest('pub(metadata.provide)', definition);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.default = Metadata;
|