@subwallet/extension-base 1.1.68-2 → 1.2.2-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/background/KoniTypes.d.ts +3 -1
  2. package/background/handlers/State.d.ts +1 -78
  3. package/background/handlers/State.js +1 -428
  4. package/background/types.d.ts +1 -0
  5. package/cjs/background/handlers/State.js +1 -456
  6. package/cjs/constants/storage.js +3 -1
  7. package/cjs/koni/api/dotsama/crowdloan.js +1 -2
  8. package/cjs/koni/api/nft/acala_nft/index.js +1 -3
  9. package/cjs/koni/api/nft/assethub_nft/index.js +1 -3
  10. package/cjs/koni/api/nft/assethub_unique/index.js +1 -3
  11. package/cjs/koni/api/nft/bit.country/index.js +4 -6
  12. package/cjs/koni/api/nft/config.js +1 -8
  13. package/cjs/koni/api/nft/evm_nft/index.js +1 -3
  14. package/cjs/koni/api/nft/karura_nft/index.js +1 -3
  15. package/cjs/koni/api/nft/ordinal_nft/index.js +4 -3
  16. package/cjs/koni/api/nft/rmrk_nft/index.js +4 -6
  17. package/cjs/koni/api/nft/unique_network_nft/index.js +1 -3
  18. package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +1 -3
  19. package/cjs/koni/api/nft/vara_nft/index.js +1 -3
  20. package/cjs/koni/api/nft/wasm_nft/index.js +10 -17
  21. package/cjs/koni/api/staking/bonding/astar.js +2 -4
  22. package/cjs/koni/api/staking/subsquidStaking.js +9 -12
  23. package/cjs/koni/api/subquery/subquery.js +1 -3
  24. package/cjs/koni/background/handlers/Extension.js +39 -15
  25. package/cjs/koni/background/handlers/Mobile.js +7 -4
  26. package/cjs/koni/background/handlers/State.js +68 -12
  27. package/cjs/koni/background/handlers/Tabs.js +7 -3
  28. package/cjs/koni/background/handlers/index.js +71 -71
  29. package/cjs/koni/background/subscription.js +7 -6
  30. package/cjs/packageInfo.js +1 -1
  31. package/cjs/services/campaign-service/helpers.js +3 -1
  32. package/cjs/services/chain-service/index.js +36 -27
  33. package/cjs/services/chain-service/utils/patch.js +1 -3
  34. package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -2
  35. package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -3
  36. package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -3
  37. package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -2
  38. package/cjs/services/earning-service/handlers/native-staking/astar.js +3 -4
  39. package/cjs/services/event-service/index.js +0 -1
  40. package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -3
  41. package/cjs/services/keyring-service/index.js +22 -0
  42. package/cjs/services/migration-service/scripts/MigrateRemoveGenesisHash.js +28 -0
  43. package/cjs/services/migration-service/scripts/index.js +3 -1
  44. package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +16 -21
  45. package/cjs/services/notification-service/NotificationService.js +3 -1
  46. package/cjs/services/price-service/coingecko.js +6 -7
  47. package/cjs/services/price-service/index.js +7 -3
  48. package/cjs/services/request-service/handler/PopupHandler.js +14 -15
  49. package/cjs/services/setting-service/SettingService.js +4 -1
  50. package/cjs/services/setting-service/constants.js +1 -1
  51. package/cjs/services/setting-service/i18n/i18n.js +2 -4
  52. package/cjs/services/storage-service/DatabaseService.js +1 -1
  53. package/cjs/services/storage-service/databases/index.js +14 -1
  54. package/cjs/services/storage-service/db-stores/KeyValue.js +13 -0
  55. package/cjs/services/subscan-service/index.js +11 -3
  56. package/cjs/services/transaction-service/index.js +3 -3
  57. package/cjs/services/wallet-connect-service/constants.js +2 -2
  58. package/cjs/services/wallet-connect-service/helpers.js +1 -4
  59. package/cjs/services/wallet-connect-service/index.js +50 -33
  60. package/cjs/storage/index.js +120 -23
  61. package/cjs/types/common/index.js +16 -0
  62. package/cjs/types/common/storage.js +1 -0
  63. package/cjs/types/index.js +11 -0
  64. package/cjs/utils/environment.js +1 -1
  65. package/cjs/utils/eth/parseTransaction/index.js +8 -10
  66. package/cjs/utils/fetch.js +55 -0
  67. package/cjs/utils/fetchStaticCache.js +2 -4
  68. package/cjs/utils/fetchStaticData.js +7 -4
  69. package/cjs/utils/index.js +24 -0
  70. package/cjs/utils/reportError.js +1 -3
  71. package/constants/storage.d.ts +1 -0
  72. package/constants/storage.js +1 -0
  73. package/koni/api/dotsama/crowdloan.js +2 -3
  74. package/koni/api/nft/acala_nft/index.js +0 -1
  75. package/koni/api/nft/assethub_nft/index.js +0 -1
  76. package/koni/api/nft/assethub_unique/index.js +0 -1
  77. package/koni/api/nft/bit.country/index.js +0 -1
  78. package/koni/api/nft/config.js +1 -7
  79. package/koni/api/nft/evm_nft/index.js +0 -1
  80. package/koni/api/nft/karura_nft/index.js +0 -1
  81. package/koni/api/nft/ordinal_nft/index.d.ts +2 -0
  82. package/koni/api/nft/ordinal_nft/index.js +4 -3
  83. package/koni/api/nft/rmrk_nft/index.js +0 -1
  84. package/koni/api/nft/unique_network_nft/index.js +0 -1
  85. package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
  86. package/koni/api/nft/vara_nft/index.js +0 -1
  87. package/koni/api/nft/wasm_nft/index.js +4 -10
  88. package/koni/api/staking/bonding/astar.js +0 -1
  89. package/koni/api/staking/subsquidStaking.js +10 -12
  90. package/koni/api/subquery/subquery.js +0 -1
  91. package/koni/background/handlers/Extension.d.ts +4 -0
  92. package/koni/background/handlers/Extension.js +29 -8
  93. package/koni/background/handlers/Mobile.js +9 -6
  94. package/koni/background/handlers/State.d.ts +6 -1
  95. package/koni/background/handlers/State.js +68 -12
  96. package/koni/background/handlers/Tabs.js +7 -3
  97. package/koni/background/handlers/index.d.ts +13 -7
  98. package/koni/background/handlers/index.js +67 -62
  99. package/koni/background/subscription.js +2 -1
  100. package/package.json +35 -28
  101. package/packageInfo.js +1 -1
  102. package/services/campaign-service/helpers.js +3 -1
  103. package/services/chain-service/index.js +36 -28
  104. package/services/chain-service/utils/patch.js +0 -1
  105. package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
  106. package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +0 -1
  107. package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -1
  108. package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -1
  109. package/services/earning-service/handlers/native-staking/astar.js +0 -1
  110. package/services/event-service/index.js +0 -1
  111. package/services/history-service/subsquid-multi-chain-history.js +0 -1
  112. package/services/keyring-service/index.d.ts +1 -0
  113. package/services/keyring-service/index.js +19 -0
  114. package/services/migration-service/scripts/MigrateRemoveGenesisHash.d.ts +4 -0
  115. package/services/migration-service/scripts/MigrateRemoveGenesisHash.js +20 -0
  116. package/services/migration-service/scripts/index.js +3 -1
  117. package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +17 -21
  118. package/services/notification-service/NotificationService.js +3 -1
  119. package/services/price-service/coingecko.js +6 -6
  120. package/services/price-service/index.js +7 -3
  121. package/services/request-service/handler/PopupHandler.d.ts +1 -1
  122. package/services/request-service/handler/PopupHandler.js +14 -15
  123. package/services/setting-service/SettingService.d.ts +1 -0
  124. package/services/setting-service/SettingService.js +4 -1
  125. package/services/setting-service/constants.js +2 -2
  126. package/services/setting-service/i18n/i18n.js +2 -4
  127. package/services/storage-service/DatabaseService.js +1 -1
  128. package/services/storage-service/databases/index.d.ts +8 -0
  129. package/services/storage-service/databases/index.js +13 -1
  130. package/services/storage-service/db-stores/KeyValue.d.ts +4 -0
  131. package/services/storage-service/db-stores/KeyValue.js +5 -0
  132. package/services/subscan-service/index.d.ts +2 -0
  133. package/services/subscan-service/index.js +10 -1
  134. package/services/transaction-service/index.js +4 -4
  135. package/services/wallet-connect-service/constants.js +3 -3
  136. package/services/wallet-connect-service/helpers.js +1 -4
  137. package/services/wallet-connect-service/index.d.ts +2 -0
  138. package/services/wallet-connect-service/index.js +42 -31
  139. package/storage/index.d.ts +19 -9
  140. package/storage/index.js +115 -23
  141. package/types/common/index.d.ts +1 -0
  142. package/types/common/index.js +4 -0
  143. package/types/common/storage.d.ts +4 -0
  144. package/types/common/storage.js +1 -0
  145. package/types/index.d.ts +1 -0
  146. package/types/index.js +1 -0
  147. package/utils/environment.js +1 -1
  148. package/utils/eth/parseTransaction/index.js +8 -10
  149. package/utils/fetch.d.ts +8 -0
  150. package/utils/fetch.js +44 -0
  151. package/utils/fetchStaticCache.js +2 -3
  152. package/utils/fetchStaticData.d.ts +1 -1
  153. package/utils/fetchStaticData.js +7 -4
  154. package/utils/index.d.ts +2 -0
  155. package/utils/index.js +2 -0
  156. package/utils/reportError.js +0 -1
  157. package/background/handlers/Extension.d.ts +0 -55
  158. package/background/handlers/Extension.js +0 -601
  159. package/background/handlers/Tabs.d.ts +0 -24
  160. package/background/handlers/Tabs.js +0 -194
  161. package/background/handlers/index.d.ts +0 -3
  162. package/background/handlers/index.js +0 -45
  163. package/cjs/background/handlers/Extension.js +0 -642
  164. package/cjs/background/handlers/Tabs.js +0 -222
  165. package/cjs/background/handlers/index.js +0 -54
  166. package/cjs/koni/background/events.js +0 -14
  167. package/koni/background/events.d.ts +0 -1
  168. package/koni/background/events.js +0 -7
@@ -1,642 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.SEED_LENGTHS = exports.SEED_DEFAULT_LENGTH = exports.ETH_DERIVE_DEFAULT = void 0;
8
- exports.getSuri = getSuri;
9
- exports.isJsonPayload = isJsonPayload;
10
- var _defaults = require("@subwallet/extension-base/defaults");
11
- var _uiKeyring = _interopRequireDefault(require("@subwallet/ui-keyring"));
12
- var _accounts = require("@subwallet/ui-keyring/observable/accounts");
13
- var _types = require("@polkadot/types");
14
- var _util = require("@polkadot/util");
15
- var _utilCrypto = require("@polkadot/util-crypto");
16
- var _helpers = require("./helpers");
17
- var _subscriptions = require("./subscriptions");
18
- // Copyright 2019-2022 @polkadot/extension authors & contributors
19
- // SPDX-License-Identifier: Apache-2.0
20
-
21
- const SEED_DEFAULT_LENGTH = 12;
22
- exports.SEED_DEFAULT_LENGTH = SEED_DEFAULT_LENGTH;
23
- const SEED_LENGTHS = [12, 15, 18, 21, 24];
24
- exports.SEED_LENGTHS = SEED_LENGTHS;
25
- const ETH_DERIVE_DEFAULT = '/m/44\'/60\'/0\'/0/0';
26
-
27
- // a global registry to use internally
28
- exports.ETH_DERIVE_DEFAULT = ETH_DERIVE_DEFAULT;
29
- const registry = new _types.TypeRegistry();
30
- function getSuri(seed, type) {
31
- return type === 'ethereum' ? `${seed}${ETH_DERIVE_DEFAULT}` : seed;
32
- }
33
- function transformAccounts(accounts) {
34
- return Object.values(accounts).map(_ref => {
35
- let {
36
- json: {
37
- address,
38
- meta
39
- },
40
- type
41
- } = _ref;
42
- return {
43
- address,
44
- ...meta,
45
- type
46
- };
47
- });
48
- }
49
- function isJsonPayload(value) {
50
- return value.genesisHash !== undefined;
51
- }
52
- class Extension {
53
- #state;
54
- constructor(state) {
55
- this.cachedUnlocks = {};
56
- this.#state = state;
57
- }
58
- accountsCreateExternal(_ref2) {
59
- let {
60
- address,
61
- genesisHash,
62
- name
63
- } = _ref2;
64
- _uiKeyring.default.addExternal(address, {
65
- genesisHash,
66
- name
67
- });
68
- return true;
69
- }
70
- accountsCreateHardware(_ref3) {
71
- let {
72
- accountIndex,
73
- address,
74
- addressOffset,
75
- genesisHash,
76
- hardwareType,
77
- name
78
- } = _ref3;
79
- _uiKeyring.default.addHardware(address, hardwareType, {
80
- accountIndex,
81
- addressOffset,
82
- genesisHash,
83
- name
84
- });
85
- return true;
86
- }
87
- accountsCreateSuri(_ref4) {
88
- let {
89
- genesisHash,
90
- name,
91
- suri,
92
- type
93
- } = _ref4;
94
- _uiKeyring.default.addUri(getSuri(suri, type), {
95
- genesisHash,
96
- name
97
- }, type);
98
- return true;
99
- }
100
- accountsChangePassword(_ref5) {
101
- let {
102
- address,
103
- newPass,
104
- oldPass
105
- } = _ref5;
106
- const pair = _uiKeyring.default.getPair(address);
107
- (0, _util.assert)(pair, 'Unable to find account');
108
- try {
109
- if (!pair.isLocked) {
110
- pair.lock();
111
- }
112
- pair.decodePkcs8(oldPass);
113
- } catch (error) {
114
- throw new Error('Wrong password');
115
- }
116
- _uiKeyring.default.encryptAccount(pair, newPass);
117
- return true;
118
- }
119
- accountsEdit(_ref6) {
120
- let {
121
- address,
122
- name
123
- } = _ref6;
124
- const pair = _uiKeyring.default.getPair(address);
125
- (0, _util.assert)(pair, 'Unable to find account');
126
- _uiKeyring.default.saveAccountMeta(pair, {
127
- ...pair.meta,
128
- name
129
- });
130
- return true;
131
- }
132
- accountsExport(_ref7) {
133
- let {
134
- address,
135
- password
136
- } = _ref7;
137
- return {
138
- exportedJson: _uiKeyring.default.backupAccount(_uiKeyring.default.getPair(address), password)
139
- };
140
- }
141
-
142
- // private async accountsBatchExport ({ addresses, password }: RequestAccountBatchExport): Promise<ResponseAccountsExport> {
143
- // return {
144
- // exportedJson: await keyring.backupAccounts(addresses, password)
145
- // };
146
- // }
147
-
148
- accountsForget(_ref8) {
149
- let {
150
- address
151
- } = _ref8;
152
- _uiKeyring.default.forgetAccount(address);
153
- return true;
154
- }
155
- refreshAccountPasswordCache(pair) {
156
- const {
157
- address
158
- } = pair;
159
- const savedExpiry = this.cachedUnlocks[address] || 0;
160
- const remainingTime = savedExpiry - Date.now();
161
- if (remainingTime < 0) {
162
- this.cachedUnlocks[address] = 0;
163
- pair.lock();
164
- return 0;
165
- }
166
- return remainingTime;
167
- }
168
- accountsShow(_ref9) {
169
- let {
170
- address,
171
- isShowing
172
- } = _ref9;
173
- const pair = _uiKeyring.default.getPair(address);
174
- (0, _util.assert)(pair, 'Unable to find account');
175
- _uiKeyring.default.saveAccountMeta(pair, {
176
- ...pair.meta,
177
- isHidden: !isShowing
178
- });
179
- return true;
180
- }
181
- accountsTie(_ref10) {
182
- let {
183
- address,
184
- genesisHash
185
- } = _ref10;
186
- const pair = _uiKeyring.default.getPair(address);
187
- (0, _util.assert)(pair, 'Unable to find account');
188
- _uiKeyring.default.saveAccountMeta(pair, {
189
- ...pair.meta,
190
- genesisHash
191
- });
192
- return true;
193
- }
194
- accountsValidate(_ref11) {
195
- let {
196
- address,
197
- password
198
- } = _ref11;
199
- try {
200
- _uiKeyring.default.backupAccount(_uiKeyring.default.getPair(address), password);
201
- return true;
202
- } catch (e) {
203
- return false;
204
- }
205
- }
206
-
207
- // FIXME This looks very much like what we have in Tabs
208
- accountsSubscribe(id, port) {
209
- const cb = (0, _subscriptions.createSubscription)(id, port);
210
- const subscription = _accounts.accounts.subject.subscribe(accounts => cb(transformAccounts(accounts)));
211
- port.onDisconnect.addListener(() => {
212
- (0, _subscriptions.unsubscribe)(id);
213
- subscription.unsubscribe();
214
- });
215
- return transformAccounts(_accounts.accounts.subject.getValue());
216
- }
217
- authorizeApprove(_ref12) {
218
- let {
219
- id
220
- } = _ref12;
221
- const queued = this.#state.getAuthRequest(id);
222
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
223
- const {
224
- resolve
225
- } = queued;
226
- resolve(true);
227
- return true;
228
- }
229
- getAuthList() {
230
- return {
231
- list: this.#state.authUrls
232
- };
233
- }
234
- authorizeReject(_ref13) {
235
- let {
236
- id
237
- } = _ref13;
238
- const queued = this.#state.getAuthRequest(id);
239
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
240
- const {
241
- reject
242
- } = queued;
243
- reject(new Error('Rejected'));
244
- return true;
245
- }
246
-
247
- // FIXME This looks very much like what we have in accounts
248
- authorizeSubscribe(id, port) {
249
- const cb = (0, _subscriptions.createSubscription)(id, port);
250
- const subscription = this.#state.authSubject.subscribe(requests => cb(requests));
251
- port.onDisconnect.addListener(() => {
252
- (0, _subscriptions.unsubscribe)(id);
253
- subscription.unsubscribe();
254
- });
255
- return true;
256
- }
257
- metadataApprove(_ref14) {
258
- let {
259
- id
260
- } = _ref14;
261
- const queued = this.#state.getMetaRequest(id);
262
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
263
- const {
264
- request,
265
- resolve
266
- } = queued;
267
- this.#state.saveMetadata(request);
268
- resolve(true);
269
- return true;
270
- }
271
- metadataGet(genesisHash) {
272
- return this.#state.knownMetadata.find(result => result.genesisHash === genesisHash) || null;
273
- }
274
- metadataList() {
275
- return this.#state.knownMetadata;
276
- }
277
- metadataReject(_ref15) {
278
- let {
279
- id
280
- } = _ref15;
281
- const queued = this.#state.getMetaRequest(id);
282
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
283
- const {
284
- reject
285
- } = queued;
286
- reject(new Error('Rejected'));
287
- return true;
288
- }
289
- metadataSubscribe(id, port) {
290
- const cb = (0, _subscriptions.createSubscription)(id, port);
291
- const subscription = this.#state.metaSubject.subscribe(requests => cb(requests));
292
- port.onDisconnect.addListener(() => {
293
- (0, _subscriptions.unsubscribe)(id);
294
- subscription.unsubscribe();
295
- });
296
- return this.#state.metaSubject.value;
297
- }
298
- jsonRestore(_ref16) {
299
- let {
300
- file,
301
- password
302
- } = _ref16;
303
- try {
304
- _uiKeyring.default.restoreAccount(file, password, true);
305
- } catch (error) {
306
- throw new Error(error.message);
307
- }
308
- }
309
- batchRestore(_ref17) {
310
- let {
311
- file,
312
- password
313
- } = _ref17;
314
- try {
315
- _uiKeyring.default.restoreAccounts(file, password);
316
- } catch (error) {
317
- throw new Error(error.message);
318
- }
319
- }
320
- jsonGetAccountInfo(json) {
321
- try {
322
- const {
323
- address,
324
- meta: {
325
- genesisHash,
326
- name
327
- },
328
- type
329
- } = _uiKeyring.default.createFromJson(json);
330
- return {
331
- address,
332
- genesisHash,
333
- name,
334
- type
335
- };
336
- } catch (e) {
337
- console.error(e);
338
- throw new Error(e.message);
339
- }
340
- }
341
- seedCreate(_ref18) {
342
- let {
343
- length = SEED_DEFAULT_LENGTH,
344
- seed: _seed,
345
- type
346
- } = _ref18;
347
- const seed = _seed || (0, _utilCrypto.mnemonicGenerate)(length);
348
- return {
349
- address: _uiKeyring.default.createFromUri(getSuri(seed, type), {}, type).address,
350
- seed
351
- };
352
- }
353
- seedValidate(_ref19) {
354
- let {
355
- suri,
356
- type
357
- } = _ref19;
358
- const {
359
- phrase
360
- } = (0, _utilCrypto.keyExtractSuri)(suri);
361
- if ((0, _util.isHex)(phrase)) {
362
- (0, _util.assert)((0, _util.isHex)(phrase, 256), 'Invalid seed phrase. Please try again.');
363
- } else {
364
- // sadly isHex detects as string, so we need a cast here
365
- (0, _util.assert)(SEED_LENGTHS.includes(phrase.split(' ').length), `Mnemonic needs to contain ${SEED_LENGTHS.join(', ')} words`);
366
- (0, _util.assert)((0, _utilCrypto.mnemonicValidate)(phrase), 'Invalid seed phrase. Please try again.');
367
- }
368
- return {
369
- address: _uiKeyring.default.createFromUri(getSuri(suri, type), {}, type).address,
370
- suri
371
- };
372
- }
373
- signingApprovePassword(_ref20) {
374
- let {
375
- id,
376
- password,
377
- savePass
378
- } = _ref20;
379
- const queued = this.#state.getSignRequest(id);
380
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
381
- const {
382
- reject,
383
- request,
384
- resolve
385
- } = queued;
386
- const pair = _uiKeyring.default.getPair(queued.account.address);
387
-
388
- // unlike queued.account.address the following
389
- // address is encoded with the default prefix
390
- // which what is used for password caching mapping
391
- const {
392
- address
393
- } = pair;
394
- if (!pair) {
395
- reject(new Error('Unable to find account'));
396
- return false;
397
- }
398
- this.refreshAccountPasswordCache(pair);
399
-
400
- // if the keyring pair is locked, the password is needed
401
- if (pair.isLocked && !password) {
402
- reject(new Error('Password needed to unlock the account'));
403
- }
404
- if (pair.isLocked) {
405
- pair.decodePkcs8(password);
406
- }
407
- const {
408
- payload
409
- } = request;
410
- if (isJsonPayload(payload)) {
411
- // Get the metadata for the genesisHash
412
- const currentMetadata = this.#state.knownMetadata.find(meta => meta.genesisHash === payload.genesisHash);
413
-
414
- // set the registry before calling the sign function
415
- registry.setSignedExtensions(payload.signedExtensions, currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.userExtensions);
416
- if (currentMetadata) {
417
- registry.register(currentMetadata === null || currentMetadata === void 0 ? void 0 : currentMetadata.types);
418
- }
419
- }
420
- const result = request.sign(registry, pair);
421
- if (savePass) {
422
- this.cachedUnlocks[address] = Date.now() + _defaults.PASSWORD_EXPIRY_MS;
423
- } else {
424
- pair.lock();
425
- }
426
- resolve({
427
- id,
428
- ...result
429
- });
430
- return true;
431
- }
432
- signingApproveSignature(_ref21) {
433
- let {
434
- id,
435
- signature
436
- } = _ref21;
437
- const queued = this.#state.getSignRequest(id);
438
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
439
- const {
440
- resolve
441
- } = queued;
442
- resolve({
443
- id,
444
- signature
445
- });
446
- return true;
447
- }
448
- signingCancel(_ref22) {
449
- let {
450
- id
451
- } = _ref22;
452
- const queued = this.#state.getSignRequest(id);
453
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
454
- const {
455
- reject
456
- } = queued;
457
- reject(new Error('Cancelled'));
458
- return true;
459
- }
460
- signingIsLocked(_ref23) {
461
- let {
462
- id
463
- } = _ref23;
464
- const queued = this.#state.getSignRequest(id);
465
- (0, _util.assert)(queued, 'Unable to proceed. Please try again');
466
- const address = queued.request.payload.address;
467
- const pair = _uiKeyring.default.getPair(address);
468
- (0, _util.assert)(pair, 'Unable to find account');
469
- const remainingTime = this.refreshAccountPasswordCache(pair);
470
- return {
471
- isLocked: pair.isLocked,
472
- remainingTime
473
- };
474
- }
475
-
476
- // FIXME This looks very much like what we have in authorization
477
- signingSubscribe(id, port) {
478
- const cb = (0, _subscriptions.createSubscription)(id, port);
479
- const subscription = this.#state.signSubject.subscribe(requests => cb(requests));
480
- port.onDisconnect.addListener(() => {
481
- (0, _subscriptions.unsubscribe)(id);
482
- subscription.unsubscribe();
483
- });
484
- return this.#state.signSubject.value;
485
- }
486
- windowOpen(_ref24) {
487
- let {
488
- allowedPath: path,
489
- params,
490
- subPath
491
- } = _ref24;
492
- let paramString = '';
493
- if (params) {
494
- paramString += '?';
495
- for (let i = 0; i < Object.keys(params).length; i++) {
496
- const [key, value] = Object.entries(params)[i];
497
- paramString += `${key}=${value}`;
498
- if (i !== Object.keys(params).length - 1) {
499
- paramString += '&';
500
- }
501
- }
502
- }
503
- const url = `${chrome.extension.getURL('index.html')}#${path}${subPath || ''}${paramString}`;
504
- if (!_defaults.ALLOWED_PATH.includes(path)) {
505
- console.error('Not allowed to open the url:', url);
506
- return false;
507
- }
508
- (0, _helpers.withErrorLog)(() => chrome.tabs.create({
509
- url
510
- }));
511
- return true;
512
- }
513
- derive(parentAddress, suri, password, metadata) {
514
- const parentPair = _uiKeyring.default.getPair(parentAddress);
515
- try {
516
- parentPair.decodePkcs8(password);
517
- } catch (e) {
518
- throw new Error('Wrong password');
519
- }
520
- try {
521
- return parentPair.derive(suri, metadata);
522
- } catch (err) {
523
- throw new Error(`"${suri}" is not a valid derivation path`);
524
- }
525
- }
526
- derivationValidate(_ref25) {
527
- let {
528
- parentAddress,
529
- parentPassword,
530
- suri
531
- } = _ref25;
532
- const childPair = this.derive(parentAddress, suri, parentPassword, {});
533
- return {
534
- address: childPair.address,
535
- suri
536
- };
537
- }
538
- derivationCreate(_ref26) {
539
- let {
540
- genesisHash,
541
- name,
542
- parentAddress,
543
- parentPassword,
544
- suri
545
- } = _ref26;
546
- const childPair = this.derive(parentAddress, suri, parentPassword, {
547
- genesisHash,
548
- name,
549
- parentAddress,
550
- suri
551
- });
552
- _uiKeyring.default.addPair(childPair, true);
553
- return true;
554
- }
555
- toggleAuthorization(url) {
556
- return {
557
- list: this.#state.toggleAuthorization(url)
558
- };
559
- }
560
-
561
- // Weird thought, the eslint override is not needed in Tabs
562
- // eslint-disable-next-line @typescript-eslint/require-await
563
- async handle(id, type, request, port) {
564
- switch (type) {
565
- case 'pri(authorize.approve)':
566
- return this.authorizeApprove(request);
567
- case 'pri(authorize.list)':
568
- return this.getAuthList();
569
- case 'pri(authorize.reject)':
570
- return this.authorizeReject(request);
571
- case 'pri(authorize.toggle)':
572
- return this.toggleAuthorization(request);
573
- case 'pri(authorize.requests)':
574
- return this.authorizeSubscribe(id, port);
575
- case 'pri(accounts.create.external)':
576
- return this.accountsCreateExternal(request);
577
- case 'pri(accounts.create.hardware)':
578
- return this.accountsCreateHardware(request);
579
- case 'pri(accounts.create.suri)':
580
- return this.accountsCreateSuri(request);
581
- case 'pri(accounts.changePassword)':
582
- return this.accountsChangePassword(request);
583
- case 'pri(accounts.edit)':
584
- return this.accountsEdit(request);
585
- case 'pri(accounts.export)':
586
- return this.accountsExport(request);
587
- case 'pri(accounts.batchExport)':
588
- // return this.accountsBatchExport(request as RequestAccountBatchExport);
589
- // Disable export all util use master password
590
- return null;
591
- case 'pri(accounts.forget)':
592
- return this.accountsForget(request);
593
- case 'pri(accounts.show)':
594
- return this.accountsShow(request);
595
- case 'pri(accounts.subscribe)':
596
- return this.accountsSubscribe(id, port);
597
- case 'pri(accounts.tie)':
598
- return this.accountsTie(request);
599
- case 'pri(accounts.validate)':
600
- return this.accountsValidate(request);
601
- case 'pri(metadata.approve)':
602
- return this.metadataApprove(request);
603
- case 'pri(metadata.get)':
604
- return this.metadataGet(request);
605
- case 'pri(metadata.list)':
606
- return this.metadataList();
607
- case 'pri(metadata.reject)':
608
- return this.metadataReject(request);
609
- case 'pri(metadata.requests)':
610
- return this.metadataSubscribe(id, port);
611
- case 'pri(derivation.create)':
612
- return this.derivationCreate(request);
613
- case 'pri(derivation.validate)':
614
- return this.derivationValidate(request);
615
- case 'pri(json.restore)':
616
- return this.jsonRestore(request);
617
- case 'pri(json.batchRestore)':
618
- return this.batchRestore(request);
619
- case 'pri(json.account.info)':
620
- return this.jsonGetAccountInfo(request);
621
- case 'pri(seed.create)':
622
- return this.seedCreate(request);
623
- case 'pri(seed.validate)':
624
- return this.seedValidate(request);
625
- case 'pri(signing.approve.password)':
626
- return this.signingApprovePassword(request);
627
- case 'pri(signing.approve.signature)':
628
- return this.signingApproveSignature(request);
629
- case 'pri(signing.cancel)':
630
- return this.signingCancel(request);
631
- case 'pri(signing.isLocked)':
632
- return this.signingIsLocked(request);
633
- case 'pri(signing.requests)':
634
- return this.signingSubscribe(id, port);
635
- case 'pri(window.open)':
636
- return this.windowOpen(request);
637
- default:
638
- throw new Error(`Unable to handle message of type ${type}`);
639
- }
640
- }
641
- }
642
- exports.default = Extension;