@subwallet/extension-base 1.0.1 → 1.0.2-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.
Files changed (169) hide show
  1. package/background/KoniTypes.d.ts +10 -3
  2. package/background/KoniTypes.js +6 -0
  3. package/cjs/background/KoniTypes.js +8 -1
  4. package/cjs/constants/index.js +6 -3
  5. package/cjs/koni/api/dotsama/balance.js +11 -0
  6. package/cjs/koni/api/staking/bonding/amplitude.js +6 -2
  7. package/cjs/koni/api/staking/bonding/astar.js +40 -243
  8. package/cjs/koni/api/staking/bonding/index.js +4 -4
  9. package/cjs/koni/api/staking/bonding/paraChain.js +16 -10
  10. package/cjs/koni/api/staking/bonding/relayChain.js +62 -7
  11. package/cjs/koni/api/staking/bonding/utils.js +29 -3
  12. package/cjs/koni/api/xcm/index.js +0 -111
  13. package/cjs/koni/api/xcm/polkadotXcm.js +1 -1
  14. package/cjs/koni/api/xcm/xTokens.js +2 -4
  15. package/cjs/koni/background/cron.js +61 -62
  16. package/cjs/koni/background/handlers/Extension.js +143 -149
  17. package/cjs/koni/background/handlers/State.js +129 -91
  18. package/cjs/koni/background/handlers/Tabs.js +40 -38
  19. package/cjs/koni/background/subscription.js +48 -43
  20. package/cjs/packageInfo.js +1 -1
  21. package/cjs/page/index.js +5 -0
  22. package/cjs/services/chain-service/constants.js +1 -11
  23. package/cjs/services/chain-service/index.js +39 -5
  24. package/cjs/services/chain-service/utils.js +4 -0
  25. package/cjs/services/event-service/index.js +71 -0
  26. package/cjs/services/event-service/types.js +1 -0
  27. package/cjs/services/history-service/index.js +36 -17
  28. package/cjs/services/history-service/subsquid-multi-chain-history.js +7 -2
  29. package/cjs/services/keyring-service/index.js +101 -0
  30. package/cjs/services/migration-service/index.js +13 -10
  31. package/cjs/{koni/migration/scripts/RemoveWrongCrowdloan.js → services/migration-service/scripts/AutoEnableChainsTokens.js} +11 -6
  32. package/cjs/services/migration-service/scripts/MigrateNetworkSettings.js +39 -19
  33. package/cjs/services/migration-service/scripts/MigrateSettings.js +31 -0
  34. package/cjs/services/migration-service/scripts/MigrateTransactionHistory.js +72 -0
  35. package/cjs/services/migration-service/scripts/index.js +13 -4
  36. package/cjs/services/price-service/coingecko.js +16 -3
  37. package/cjs/services/price-service/index.js +15 -17
  38. package/cjs/services/request-service/constants.js +8 -2
  39. package/cjs/services/request-service/handler/AuthRequestHandler.js +39 -12
  40. package/cjs/services/request-service/index.js +3 -0
  41. package/cjs/services/storage-service/DatabaseService.js +1 -1
  42. package/cjs/services/storage-service/databases/index.js +1 -1
  43. package/cjs/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  44. package/cjs/services/storage-service/db-stores/Nft.js +4 -1
  45. package/cjs/services/storage-service/db-stores/Transaction.js +10 -7
  46. package/cjs/services/subscan-service/index.js +107 -0
  47. package/cjs/services/subscan-service/subscan-chain-map.js +74 -0
  48. package/cjs/services/subscan-service/types.js +1 -0
  49. package/cjs/services/transaction-service/index.js +45 -10
  50. package/cjs/services/transaction-service/utils.js +4 -6
  51. package/cjs/utils/address.js +9 -1
  52. package/cjs/utils/index.js +24 -13
  53. package/constants/index.d.ts +1 -0
  54. package/constants/index.js +1 -0
  55. package/koni/api/dotsama/balance.js +11 -0
  56. package/koni/api/staking/bonding/amplitude.d.ts +1 -1
  57. package/koni/api/staking/bonding/amplitude.js +8 -4
  58. package/koni/api/staking/bonding/astar.d.ts +2 -11
  59. package/koni/api/staking/bonding/astar.js +35 -229
  60. package/koni/api/staking/bonding/index.d.ts +1 -1
  61. package/koni/api/staking/bonding/index.js +4 -4
  62. package/koni/api/staking/bonding/paraChain.d.ts +1 -1
  63. package/koni/api/staking/bonding/paraChain.js +17 -11
  64. package/koni/api/staking/bonding/relayChain.d.ts +1 -1
  65. package/koni/api/staking/bonding/relayChain.js +63 -8
  66. package/koni/api/staking/bonding/utils.d.ts +13 -1
  67. package/koni/api/staking/bonding/utils.js +27 -3
  68. package/koni/api/xcm/index.js +1 -112
  69. package/koni/api/xcm/polkadotXcm.js +1 -1
  70. package/koni/api/xcm/xTokens.js +3 -5
  71. package/koni/background/cron.js +60 -60
  72. package/koni/background/handlers/Extension.js +71 -76
  73. package/koni/background/handlers/State.d.ts +16 -14
  74. package/koni/background/handlers/State.js +126 -91
  75. package/koni/background/handlers/Tabs.js +22 -19
  76. package/koni/background/subscription.d.ts +1 -1
  77. package/koni/background/subscription.js +49 -44
  78. package/package.json +56 -16
  79. package/packageInfo.js +1 -1
  80. package/page/index.d.ts +2 -0
  81. package/page/index.js +4 -0
  82. package/services/chain-service/constants.d.ts +0 -1
  83. package/services/chain-service/constants.js +0 -9
  84. package/services/chain-service/index.d.ts +6 -4
  85. package/services/chain-service/index.js +39 -7
  86. package/services/chain-service/utils.d.ts +1 -0
  87. package/services/chain-service/utils.js +3 -0
  88. package/services/event-service/index.d.ts +22 -0
  89. package/services/event-service/index.js +59 -0
  90. package/services/event-service/types.d.ts +32 -0
  91. package/services/event-service/types.js +1 -0
  92. package/services/history-service/index.d.ts +5 -3
  93. package/services/history-service/index.js +36 -17
  94. package/services/history-service/subsquid-multi-chain-history.js +7 -2
  95. package/services/keyring-service/index.d.ts +19 -0
  96. package/services/keyring-service/index.js +93 -0
  97. package/services/migration-service/index.js +11 -9
  98. package/services/migration-service/scripts/AutoEnableChainsTokens.d.ts +4 -0
  99. package/services/migration-service/scripts/AutoEnableChainsTokens.js +13 -0
  100. package/services/migration-service/scripts/MigrateNetworkSettings.js +37 -18
  101. package/services/migration-service/scripts/MigrateSettings.d.ts +4 -0
  102. package/services/migration-service/scripts/MigrateSettings.js +23 -0
  103. package/services/migration-service/scripts/MigrateTransactionHistory.d.ts +4 -0
  104. package/services/migration-service/scripts/MigrateTransactionHistory.js +64 -0
  105. package/services/migration-service/scripts/index.d.ts +1 -0
  106. package/services/migration-service/scripts/index.js +10 -3
  107. package/services/price-service/coingecko.js +16 -3
  108. package/services/price-service/index.d.ts +5 -3
  109. package/services/price-service/index.js +15 -17
  110. package/services/request-service/constants.d.ts +1 -0
  111. package/services/request-service/constants.js +6 -1
  112. package/services/request-service/handler/AuthRequestHandler.d.ts +8 -1
  113. package/services/request-service/handler/AuthRequestHandler.js +40 -13
  114. package/services/request-service/index.d.ts +7 -1
  115. package/services/request-service/index.js +3 -0
  116. package/services/storage-service/DatabaseService.js +1 -1
  117. package/services/storage-service/databases/index.js +1 -1
  118. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.d.ts +1 -1
  119. package/services/storage-service/db-stores/BaseStoreWithAddressAndChain.js +2 -8
  120. package/services/storage-service/db-stores/Nft.d.ts +2 -1
  121. package/services/storage-service/db-stores/Nft.js +4 -1
  122. package/services/storage-service/db-stores/Transaction.js +10 -7
  123. package/services/subscan-service/index.d.ts +20 -0
  124. package/services/subscan-service/index.js +99 -0
  125. package/services/subscan-service/subscan-chain-map.d.ts +5 -0
  126. package/services/subscan-service/subscan-chain-map.js +63 -0
  127. package/services/subscan-service/types.d.ts +27 -0
  128. package/services/subscan-service/types.js +1 -0
  129. package/services/transaction-service/event-parser/index.d.ts +2 -2
  130. package/services/transaction-service/index.d.ts +4 -2
  131. package/services/transaction-service/index.js +45 -10
  132. package/services/transaction-service/utils.js +5 -6
  133. package/utils/address.d.ts +1 -0
  134. package/utils/address.js +9 -2
  135. package/utils/index.d.ts +1 -0
  136. package/utils/index.js +21 -12
  137. package/cjs/background/errors/EvmRpcError.js +0 -21
  138. package/cjs/background/errors/SubWalletProviderError.js +0 -17
  139. package/cjs/constants/ethereum.js +0 -19
  140. package/cjs/errors/SubWalletProviderError.js +0 -17
  141. package/cjs/koni/api/xcm/astar.js +0 -160
  142. package/cjs/koni/api/xcm/moonbeamXcm.js +0 -80
  143. package/cjs/koni/api/xcm/statemintXcm.js +0 -197
  144. package/cjs/koni/api/xcm/substrateXcm.js +0 -213
  145. package/cjs/koni/migration/Base.js +0 -20
  146. package/cjs/koni/migration/index.js +0 -45
  147. package/cjs/koni/migration/scripts/ChangeRouteToHome.js +0 -22
  148. package/cjs/koni/migration/scripts/ClearOldStorage.js +0 -24
  149. package/cjs/koni/migration/scripts/RemoveWrongTransactionHistoriesFromStore.js +0 -36
  150. package/cjs/koni/migration/scripts/ResetTransactionHistoryEventIdx.js +0 -21
  151. package/cjs/koni/migration/scripts/index.js +0 -22
  152. package/cjs/koni/page/index.js +0 -16
  153. package/cjs/services/asset-service/index.js +0 -91
  154. package/cjs/services/storage-service/db-stores/ExtraDelegationInfo.js +0 -17
  155. package/cjs/stores/Balance.js +0 -18
  156. package/cjs/stores/Crowdloan.js +0 -18
  157. package/cjs/stores/CustomEvmToken.js +0 -18
  158. package/cjs/stores/NetworkMap.js +0 -18
  159. package/cjs/stores/Nft.js +0 -18
  160. package/cjs/stores/NftCollection.js +0 -18
  161. package/cjs/stores/Price.js +0 -18
  162. package/cjs/stores/Staking.js +0 -18
  163. package/cjs/stores/StakingReward.js +0 -18
  164. package/cjs/utils/eth/parseTransactionData.js +0 -284
  165. package/koni/page/index.d.ts +0 -2
  166. package/koni/page/index.js +0 -9
  167. /package/cjs/{koni/page → page}/SubWalleEvmProvider.js +0 -0
  168. /package/{koni/page → page}/SubWalleEvmProvider.d.ts +0 -0
  169. /package/{koni/page → page}/SubWalleEvmProvider.js +0 -0
@@ -1,284 +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.InputDataDecoder = void 0;
8
- var _buffer = require("buffer");
9
- var _ethers = require("ethers");
10
- var _isBuffer = _interopRequireDefault(require("is-buffer"));
11
- var _web3Utils = require("web3-utils");
12
- // Copyright 2019-2022 @subwallet/extension-koni-base authors & contributors
13
- // SPDX-License-Identifier: Apache-2.0
14
-
15
- // @ts-ignore
16
-
17
- const ABI_TYPES = ['function', 'constructor', 'event', 'fallback'];
18
- const instanceOfAbiItem = object => {
19
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access
20
- return 'type' in object && ABI_TYPES.includes(object.type);
21
- };
22
- const checkArrayAbiItems = data => {
23
- if (Array.isArray(data)) {
24
- return data.length > 0 && data.every(value => instanceOfAbiItem(value));
25
- } else {
26
- return false;
27
- }
28
- };
29
- const genType = type => {
30
- if (typeof type === 'string') {
31
- return type;
32
- } else {
33
- if (type.components) {
34
- var _type$components;
35
- const arr = (_type$components = type.components) === null || _type$components === void 0 ? void 0 : _type$components.map(genType);
36
- const tupleStr = `(${arr.join(',')})`;
37
- if (type.type === 'tuple[]') {
38
- return tupleStr + '[]';
39
- } else {
40
- return tupleStr;
41
- }
42
- } else {
43
- return type.type;
44
- }
45
- }
46
- };
47
- const getMethodId = abi => {
48
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call
49
- return (0, _web3Utils.keccak256)((0, _web3Utils._jsonInterfaceMethodToString)(abi)).slice(2, 10);
50
- };
51
- const getMethodName = abi => {
52
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-call
53
- return (0, _web3Utils._jsonInterfaceMethodToString)(abi);
54
- };
55
- const deepRemoveUnwantedArrayProperties = arr => {
56
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-return
57
- return [...arr.map(item => {
58
- if (Array.isArray(item)) {
59
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
60
- return deepRemoveUnwantedArrayProperties(item);
61
- }
62
-
63
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
64
- return item;
65
- })];
66
- };
67
-
68
- // remove 0x from addresses
69
- function deepStripTupleAddresses(input, tupleTypes) {
70
- return input.map((item, i) => {
71
- // We find tupleTypes to not be an array where internalType is present in the ABI indicating item is a structure
72
- const type = tupleTypes[i] ? tupleTypes[i].type : null;
73
- if (type === 'address' && typeof item === 'string') {
74
- return item;
75
- }
76
- if (type === 'address[]' && Array.isArray(item)) {
77
- return item.map(a => a);
78
- }
79
- if (Array.isArray(item)) {
80
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
81
- return deepStripTupleAddresses(item, tupleTypes);
82
- }
83
-
84
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
85
- return item;
86
- });
87
- }
88
- const toHexString = byteArray => {
89
- return Array.from(byteArray, function (byte) {
90
- return ('0' + (byte & 0xFF).toString(16)).slice(-2);
91
- }).join('');
92
- };
93
- class InputDataDecoder {
94
- constructor(prop) {
95
- this.abi = [];
96
- if (typeof prop === 'string') {
97
- try {
98
- this.abi = JSON.parse(prop);
99
- } catch (err) {
100
- throw new Error(`Invalid ABI: ${err.message}`);
101
- }
102
- } else if (checkArrayAbiItems(prop)) {
103
- this.abi = prop;
104
- } else {
105
- throw new TypeError('Must pass ABI array object or file path to constructor');
106
- }
107
- }
108
- decodeConstructor(data) {
109
- if ((0, _isBuffer.default)(data)) {
110
- data = data.toString('utf8');
111
- }
112
- if (typeof data !== 'string') {
113
- data = '';
114
- }
115
- data = data.trim();
116
- for (let i = 0; i < this.abi.length; i++) {
117
- const obj = this.abi[i];
118
- if (obj.type !== 'constructor') {
119
- continue;
120
- }
121
- const method = obj.name || null;
122
- const methodName = getMethodName(obj);
123
- const types = obj.inputs ? obj.inputs.map(x => x.type) : [];
124
- const names = obj.inputs ? obj.inputs.map(x => x.name) : [];
125
-
126
- // take last 32 bytes
127
- data = data.slice(-256);
128
- if (data.length !== 256) {
129
- throw new Error('fail');
130
- }
131
- if (data.indexOf('0x') !== 0) {
132
- data = `0x${data}`;
133
- }
134
- const _inputs = _ethers.ethers.utils.defaultAbiCoder.decode(types, data);
135
- const inputs = deepRemoveUnwantedArrayProperties(_inputs);
136
- return {
137
- methodName,
138
- method,
139
- types,
140
- inputs,
141
- names
142
- };
143
- }
144
- throw new Error('not found');
145
- }
146
- decodeData(data) {
147
- if ((0, _isBuffer.default)(data)) {
148
- data = data.toString('utf8');
149
- }
150
- if (typeof data !== 'string') {
151
- data = '';
152
- }
153
- data = data.trim();
154
- const dataBuf = _buffer.Buffer.from(data.replace(/^0x/, ''), 'hex');
155
- const methodId = toHexString(dataBuf.subarray(0, 4));
156
- const inputsBuf = dataBuf.subarray(4);
157
- let result = {
158
- method: null,
159
- methodName: null,
160
- types: [],
161
- inputs: [],
162
- names: []
163
- };
164
- for (const abi of this.abi) {
165
- try {
166
- if (abi.type === 'constructor') {
167
- continue;
168
- }
169
- if (abi.type === 'event') {
170
- continue;
171
- }
172
- const method = abi.name || null;
173
- const methodName = getMethodName(abi);
174
- const types = abi.inputs ? abi.inputs.map(x => {
175
- if (x.type.includes('tuple')) {
176
- return x;
177
- } else {
178
- return x.type;
179
- }
180
- }) : [];
181
- const names = abi.inputs ? abi.inputs.map(x => {
182
- if (x.type.includes('tuple') && x.components) {
183
- return [x.name, x.components.map(a => a.name)];
184
- } else {
185
- return x.name;
186
- }
187
- }) : [];
188
- const hash = getMethodId(abi);
189
- if (hash === methodId) {
190
- let inputs = [];
191
- try {
192
- // @ts-ignore
193
- inputs = _ethers.ethers.utils.defaultAbiCoder.decode(types, inputsBuf);
194
- } catch (err) {
195
- try {
196
- const ifc = new _ethers.ethers.utils.Interface([]);
197
- inputs = ifc.decodeFunctionData(_ethers.ethers.utils.FunctionFragment.fromObject(abi), data);
198
- } catch (err) {}
199
- }
200
-
201
- // TODO: do this normalization into normalizeAddresses
202
- let _inputs = [];
203
- _inputs = inputs.map((input, i) => {
204
- if (types[i].components) {
205
- const tupleTypes = types[i].components;
206
-
207
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return,@typescript-eslint/no-unsafe-argument
208
- return deepStripTupleAddresses(input, tupleTypes);
209
- }
210
- if (types[i] === 'address' && typeof input === 'string') {
211
- return input;
212
- }
213
- if (types[i] === 'address[]' && Array.isArray(input)) {
214
- return input.map(address => address);
215
- }
216
-
217
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
218
- return input;
219
- });
220
-
221
- // Map any tuple types into arrays
222
- const typesToReturn = types.map(genType);
223
-
224
- // defaultAbiCoder attaches some unwanted properties to the list object
225
- _inputs = deepRemoveUnwantedArrayProperties(_inputs);
226
- result = {
227
- methodName,
228
- method,
229
- types: typesToReturn,
230
- inputs: _inputs,
231
- names
232
- };
233
- }
234
- } catch (err) {
235
- console.log(err);
236
- }
237
- }
238
- if (!result.method) {
239
- for (const obj of this.abi) {
240
- if (obj.type === 'constructor') {
241
- continue;
242
- }
243
- if (obj.type === 'event') {
244
- continue;
245
- }
246
- const method = obj.name || null;
247
- try {
248
- const ifc = new _ethers.ethers.utils.Interface([]);
249
- const _result = ifc.decodeFunctionData(_ethers.ethers.utils.FunctionFragment.fromObject(obj), data);
250
- const inputs = deepRemoveUnwantedArrayProperties(_result);
251
- result.method = method;
252
- result.methodName = getMethodName(obj);
253
- result.inputs = inputs;
254
- result.names = obj.inputs ? obj.inputs.map(x => {
255
- if (x.type.includes('tuple')) {
256
- var _x$components;
257
- return [x.name, ((_x$components = x.components) === null || _x$components === void 0 ? void 0 : _x$components.map(a => a.name)) || ''];
258
- } else {
259
- return x.name;
260
- }
261
- }) : [];
262
- const types = obj.inputs ? obj.inputs.map(x => {
263
- if (x.type.includes('tuple')) {
264
- return x;
265
- } else {
266
- return x.type;
267
- }
268
- }) : [];
269
- result.types = types.map(genType);
270
- } catch (err) {}
271
- }
272
- }
273
- if (!result.method) {
274
- try {
275
- const decoded = this.decodeConstructor(data);
276
- if (decoded) {
277
- return decoded;
278
- }
279
- } catch (err) {}
280
- }
281
- return result;
282
- }
283
- }
284
- exports.InputDataDecoder = InputDataDecoder;
@@ -1,2 +0,0 @@
1
- import { EvmProvider } from '@subwallet/extension-inject/types';
2
- export declare function initEvmProvider(version: string): EvmProvider;
@@ -1,9 +0,0 @@
1
- // Copyright 2019-2022 @subwallet/extension-koni authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // the enable function, called by the dapp to allow access
5
- import { SubWalletEvmProvider } from '@subwallet/extension-base/koni/page/SubWalleEvmProvider';
6
- import { sendMessage } from '@subwallet/extension-base/page';
7
- export function initEvmProvider(version) {
8
- return new SubWalletEvmProvider(sendMessage, version);
9
- }
File without changes
File without changes
File without changes