@subwallet/extension-base 1.1.68-2 → 1.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.
- package/background/KoniTypes.d.ts +3 -1
- package/background/handlers/State.d.ts +1 -78
- package/background/handlers/State.js +1 -428
- package/background/types.d.ts +1 -0
- package/cjs/background/handlers/State.js +1 -456
- package/cjs/constants/storage.js +3 -1
- package/cjs/koni/api/dotsama/crowdloan.js +1 -2
- package/cjs/koni/api/nft/acala_nft/index.js +1 -3
- package/cjs/koni/api/nft/assethub_nft/index.js +1 -3
- package/cjs/koni/api/nft/assethub_unique/index.js +1 -3
- package/cjs/koni/api/nft/bit.country/index.js +4 -6
- package/cjs/koni/api/nft/config.js +1 -8
- package/cjs/koni/api/nft/evm_nft/index.js +1 -3
- package/cjs/koni/api/nft/karura_nft/index.js +1 -3
- package/cjs/koni/api/nft/ordinal_nft/index.js +4 -3
- package/cjs/koni/api/nft/rmrk_nft/index.js +4 -6
- package/cjs/koni/api/nft/unique_network_nft/index.js +1 -3
- package/cjs/koni/api/nft/unique_nft/uniqueNftV2.js +1 -3
- package/cjs/koni/api/nft/vara_nft/index.js +1 -3
- package/cjs/koni/api/nft/wasm_nft/index.js +10 -17
- package/cjs/koni/api/staking/bonding/astar.js +2 -4
- package/cjs/koni/api/staking/subsquidStaking.js +9 -12
- package/cjs/koni/api/subquery/subquery.js +1 -3
- package/cjs/koni/background/handlers/Extension.js +39 -15
- package/cjs/koni/background/handlers/Mobile.js +7 -4
- package/cjs/koni/background/handlers/State.js +68 -12
- package/cjs/koni/background/handlers/Tabs.js +4 -1
- package/cjs/koni/background/handlers/index.js +71 -71
- package/cjs/koni/background/subscription.js +7 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/campaign-service/helpers.js +3 -1
- package/cjs/services/chain-service/index.js +36 -27
- package/cjs/services/chain-service/utils/patch.js +1 -3
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -2
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -3
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -3
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +1 -2
- package/cjs/services/earning-service/handlers/native-staking/astar.js +3 -4
- package/cjs/services/event-service/index.js +0 -1
- package/cjs/services/history-service/subsquid-multi-chain-history.js +1 -3
- package/cjs/services/keyring-service/index.js +22 -0
- package/cjs/services/migration-service/scripts/MigrateRemoveGenesisHash.js +28 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +16 -21
- package/cjs/services/notification-service/NotificationService.js +3 -1
- package/cjs/services/price-service/coingecko.js +6 -7
- package/cjs/services/price-service/index.js +7 -3
- package/cjs/services/request-service/handler/PopupHandler.js +14 -15
- package/cjs/services/setting-service/SettingService.js +4 -1
- package/cjs/services/setting-service/constants.js +1 -1
- package/cjs/services/setting-service/i18n/i18n.js +2 -4
- package/cjs/services/storage-service/DatabaseService.js +1 -1
- package/cjs/services/storage-service/databases/index.js +14 -1
- package/cjs/services/storage-service/db-stores/KeyValue.js +13 -0
- package/cjs/services/subscan-service/index.js +11 -3
- package/cjs/services/transaction-service/index.js +3 -3
- package/cjs/services/wallet-connect-service/constants.js +2 -2
- package/cjs/services/wallet-connect-service/helpers.js +1 -4
- package/cjs/services/wallet-connect-service/index.js +50 -33
- package/cjs/storage/index.js +120 -23
- package/cjs/types/common/index.js +16 -0
- package/cjs/types/common/storage.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/environment.js +1 -1
- package/cjs/utils/eth/parseTransaction/index.js +8 -10
- package/cjs/utils/fetch.js +55 -0
- package/cjs/utils/fetchStaticCache.js +2 -4
- package/cjs/utils/fetchStaticData.js +7 -4
- package/cjs/utils/index.js +24 -0
- package/cjs/utils/reportError.js +1 -3
- package/constants/storage.d.ts +1 -0
- package/constants/storage.js +1 -0
- package/koni/api/dotsama/crowdloan.js +2 -3
- package/koni/api/nft/acala_nft/index.js +0 -1
- package/koni/api/nft/assethub_nft/index.js +0 -1
- package/koni/api/nft/assethub_unique/index.js +0 -1
- package/koni/api/nft/bit.country/index.js +0 -1
- package/koni/api/nft/config.js +1 -7
- package/koni/api/nft/evm_nft/index.js +0 -1
- package/koni/api/nft/karura_nft/index.js +0 -1
- package/koni/api/nft/ordinal_nft/index.d.ts +2 -0
- package/koni/api/nft/ordinal_nft/index.js +4 -3
- package/koni/api/nft/rmrk_nft/index.js +0 -1
- package/koni/api/nft/unique_network_nft/index.js +0 -1
- package/koni/api/nft/unique_nft/uniqueNftV2.js +0 -1
- package/koni/api/nft/vara_nft/index.js +0 -1
- package/koni/api/nft/wasm_nft/index.js +4 -10
- package/koni/api/staking/bonding/astar.js +0 -1
- package/koni/api/staking/subsquidStaking.js +10 -12
- package/koni/api/subquery/subquery.js +0 -1
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +29 -8
- package/koni/background/handlers/Mobile.js +9 -6
- package/koni/background/handlers/State.d.ts +6 -1
- package/koni/background/handlers/State.js +68 -12
- package/koni/background/handlers/Tabs.js +4 -1
- package/koni/background/handlers/index.d.ts +13 -7
- package/koni/background/handlers/index.js +67 -62
- package/koni/background/subscription.js +2 -1
- package/package.json +35 -28
- package/packageInfo.js +1 -1
- package/services/campaign-service/helpers.js +3 -1
- package/services/chain-service/index.js +36 -28
- package/services/chain-service/utils/patch.js +0 -1
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +0 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +0 -1
- package/services/earning-service/handlers/native-staking/astar.js +0 -1
- package/services/event-service/index.js +0 -1
- package/services/history-service/subsquid-multi-chain-history.js +0 -1
- package/services/keyring-service/index.d.ts +1 -0
- package/services/keyring-service/index.js +19 -0
- package/services/migration-service/scripts/MigrateRemoveGenesisHash.d.ts +4 -0
- package/services/migration-service/scripts/MigrateRemoveGenesisHash.js +20 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +17 -21
- package/services/notification-service/NotificationService.js +3 -1
- package/services/price-service/coingecko.js +6 -6
- package/services/price-service/index.js +7 -3
- package/services/request-service/handler/PopupHandler.d.ts +1 -1
- package/services/request-service/handler/PopupHandler.js +14 -15
- package/services/setting-service/SettingService.d.ts +1 -0
- package/services/setting-service/SettingService.js +4 -1
- package/services/setting-service/constants.js +2 -2
- package/services/setting-service/i18n/i18n.js +2 -4
- package/services/storage-service/DatabaseService.js +1 -1
- package/services/storage-service/databases/index.d.ts +8 -0
- package/services/storage-service/databases/index.js +13 -1
- package/services/storage-service/db-stores/KeyValue.d.ts +4 -0
- package/services/storage-service/db-stores/KeyValue.js +5 -0
- package/services/subscan-service/index.d.ts +2 -0
- package/services/subscan-service/index.js +10 -1
- package/services/transaction-service/index.js +4 -4
- package/services/wallet-connect-service/constants.js +3 -3
- package/services/wallet-connect-service/helpers.js +1 -4
- package/services/wallet-connect-service/index.d.ts +2 -0
- package/services/wallet-connect-service/index.js +42 -31
- package/storage/index.d.ts +19 -9
- package/storage/index.js +115 -23
- package/types/common/index.d.ts +1 -0
- package/types/common/index.js +4 -0
- package/types/common/storage.d.ts +4 -0
- package/types/common/storage.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/utils/environment.js +1 -1
- package/utils/eth/parseTransaction/index.js +8 -10
- package/utils/fetch.d.ts +8 -0
- package/utils/fetch.js +44 -0
- package/utils/fetchStaticCache.js +2 -3
- package/utils/fetchStaticData.d.ts +1 -1
- package/utils/fetchStaticData.js +7 -4
- package/utils/index.d.ts +2 -0
- package/utils/index.js +2 -0
- package/utils/reportError.js +0 -1
- package/background/handlers/Extension.d.ts +0 -55
- package/background/handlers/Extension.js +0 -601
- package/background/handlers/Tabs.d.ts +0 -24
- package/background/handlers/Tabs.js +0 -194
- package/background/handlers/index.d.ts +0 -3
- package/background/handlers/index.js +0 -45
- package/cjs/background/handlers/Extension.js +0 -642
- package/cjs/background/handlers/Tabs.js +0 -222
- package/cjs/background/handlers/index.js +0 -54
- package/cjs/koni/background/events.js +0 -14
- package/koni/background/events.d.ts +0 -1
- package/koni/background/events.js +0 -7
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { PHISHING_PAGE_REDIRECT } from '@subwallet/extension-base/defaults';
|
|
5
|
-
import { canDerive } from '@subwallet/extension-base/utils';
|
|
6
|
-
import keyring from '@subwallet/ui-keyring';
|
|
7
|
-
import { accounts as accountsObservable } from '@subwallet/ui-keyring/observable/accounts';
|
|
8
|
-
import { checkIfDenied } from '@polkadot/phishing';
|
|
9
|
-
import { assert, isNumber } from '@polkadot/util';
|
|
10
|
-
import RequestBytesSign from "../RequestBytesSign.js";
|
|
11
|
-
import RequestExtrinsicSign from "../RequestExtrinsicSign.js";
|
|
12
|
-
import { withErrorLog } from "./helpers.js";
|
|
13
|
-
import { createSubscription, unsubscribe } from "./subscriptions.js";
|
|
14
|
-
function transformAccounts(accounts, anyType = false) {
|
|
15
|
-
return Object.values(accounts).filter(({
|
|
16
|
-
json: {
|
|
17
|
-
meta: {
|
|
18
|
-
isHidden
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}) => !isHidden).filter(({
|
|
22
|
-
type
|
|
23
|
-
}) => anyType ? true : canDerive(type)).filter(({
|
|
24
|
-
type
|
|
25
|
-
}) => type !== 'ethereum') // Quick fix DApp not allow EVM
|
|
26
|
-
.sort((a, b) => (a.json.meta.whenCreated || 0) - (b.json.meta.whenCreated || 0)).map(({
|
|
27
|
-
json: {
|
|
28
|
-
address,
|
|
29
|
-
meta: {
|
|
30
|
-
genesisHash,
|
|
31
|
-
name
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
type
|
|
35
|
-
}) => ({
|
|
36
|
-
address,
|
|
37
|
-
genesisHash,
|
|
38
|
-
name,
|
|
39
|
-
type
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
export default class Tabs {
|
|
43
|
-
#state;
|
|
44
|
-
constructor(state) {
|
|
45
|
-
this.#state = state;
|
|
46
|
-
}
|
|
47
|
-
authorize(url, request) {
|
|
48
|
-
return this.#state.authorizeUrl(url, request);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
52
|
-
accountsList(url, {
|
|
53
|
-
anyType
|
|
54
|
-
}) {
|
|
55
|
-
return transformAccounts(accountsObservable.subject.getValue(), anyType);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// FIXME This looks very much like what we have in Extension
|
|
59
|
-
accountsSubscribe(url, id, port) {
|
|
60
|
-
const cb = createSubscription(id, port);
|
|
61
|
-
const subscription = accountsObservable.subject.subscribe(accounts => cb(transformAccounts(accounts)));
|
|
62
|
-
port.onDisconnect.addListener(() => {
|
|
63
|
-
unsubscribe(id);
|
|
64
|
-
subscription.unsubscribe();
|
|
65
|
-
});
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
getSigningPair(address) {
|
|
69
|
-
const pair = keyring.getPair(address);
|
|
70
|
-
assert(pair, 'Unable to find account');
|
|
71
|
-
return pair;
|
|
72
|
-
}
|
|
73
|
-
bytesSign(url, request) {
|
|
74
|
-
const address = request.address;
|
|
75
|
-
const pair = this.getSigningPair(address);
|
|
76
|
-
return this.#state.sign(url, new RequestBytesSign(request), {
|
|
77
|
-
address,
|
|
78
|
-
...pair.meta
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
extrinsicSign(url, request) {
|
|
82
|
-
const address = request.address;
|
|
83
|
-
const pair = this.getSigningPair(address);
|
|
84
|
-
return this.#state.sign(url, new RequestExtrinsicSign(request), {
|
|
85
|
-
address,
|
|
86
|
-
...pair.meta
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
metadataProvide(url, request) {
|
|
90
|
-
return this.#state.injectMetadata(url, request);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
94
|
-
metadataList(url) {
|
|
95
|
-
return this.#state.knownMetadata.map(({
|
|
96
|
-
genesisHash,
|
|
97
|
-
specVersion
|
|
98
|
-
}) => ({
|
|
99
|
-
genesisHash,
|
|
100
|
-
specVersion
|
|
101
|
-
}));
|
|
102
|
-
}
|
|
103
|
-
rpcListProviders() {
|
|
104
|
-
return this.#state.rpcListProviders();
|
|
105
|
-
}
|
|
106
|
-
rpcSend(request, port) {
|
|
107
|
-
return this.#state.rpcSend(request, port);
|
|
108
|
-
}
|
|
109
|
-
rpcStartProvider(key, port) {
|
|
110
|
-
return this.#state.rpcStartProvider(key, port);
|
|
111
|
-
}
|
|
112
|
-
async rpcSubscribe(request, id, port) {
|
|
113
|
-
const innerCb = createSubscription(id, port);
|
|
114
|
-
const cb = (_error, data) => innerCb(data);
|
|
115
|
-
const subscriptionId = await this.#state.rpcSubscribe(request, cb, port);
|
|
116
|
-
port.onDisconnect.addListener(() => {
|
|
117
|
-
unsubscribe(id);
|
|
118
|
-
withErrorLog(() => this.rpcUnsubscribe({
|
|
119
|
-
...request,
|
|
120
|
-
subscriptionId
|
|
121
|
-
}, port));
|
|
122
|
-
});
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
rpcSubscribeConnected(request, id, port) {
|
|
126
|
-
const innerCb = createSubscription(id, port);
|
|
127
|
-
const cb = (_error, data) => innerCb(data);
|
|
128
|
-
this.#state.rpcSubscribeConnected(request, cb, port);
|
|
129
|
-
port.onDisconnect.addListener(() => {
|
|
130
|
-
unsubscribe(id);
|
|
131
|
-
});
|
|
132
|
-
return Promise.resolve(true);
|
|
133
|
-
}
|
|
134
|
-
async rpcUnsubscribe(request, port) {
|
|
135
|
-
return this.#state.rpcUnsubscribe(request, port);
|
|
136
|
-
}
|
|
137
|
-
redirectPhishingLanding(phishingWebsite) {
|
|
138
|
-
const nonFragment = phishingWebsite.split('#')[0];
|
|
139
|
-
const encodedWebsite = encodeURIComponent(nonFragment);
|
|
140
|
-
const url = `${chrome.extension.getURL('index.html')}#${PHISHING_PAGE_REDIRECT}/${encodedWebsite}`;
|
|
141
|
-
chrome.tabs.query({
|
|
142
|
-
url: nonFragment
|
|
143
|
-
}, tabs => {
|
|
144
|
-
tabs.map(({
|
|
145
|
-
id
|
|
146
|
-
}) => id).filter(id => isNumber(id)).forEach(id => withErrorLog(() => chrome.tabs.update(id, {
|
|
147
|
-
url
|
|
148
|
-
})));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async redirectIfPhishing(url) {
|
|
152
|
-
const isInDenyList = await checkIfDenied(url);
|
|
153
|
-
if (isInDenyList) {
|
|
154
|
-
this.redirectPhishingLanding(url);
|
|
155
|
-
return true;
|
|
156
|
-
}
|
|
157
|
-
return false;
|
|
158
|
-
}
|
|
159
|
-
async handle(id, type, request, url, port) {
|
|
160
|
-
if (type === 'pub(phishing.redirectIfDenied)') {
|
|
161
|
-
return this.redirectIfPhishing(url);
|
|
162
|
-
}
|
|
163
|
-
switch (type) {
|
|
164
|
-
case 'pub(authorize.tab)':
|
|
165
|
-
return this.authorize(url, request);
|
|
166
|
-
case 'pub(accounts.list)':
|
|
167
|
-
return this.accountsList(url, request);
|
|
168
|
-
case 'pub(accounts.subscribe)':
|
|
169
|
-
return this.accountsSubscribe(url, id, port);
|
|
170
|
-
case 'pub(bytes.sign)':
|
|
171
|
-
return this.bytesSign(url, request);
|
|
172
|
-
case 'pub(extrinsic.sign)':
|
|
173
|
-
return this.extrinsicSign(url, request);
|
|
174
|
-
case 'pub(metadata.list)':
|
|
175
|
-
return this.metadataList(url);
|
|
176
|
-
case 'pub(metadata.provide)':
|
|
177
|
-
return this.metadataProvide(url, request);
|
|
178
|
-
case 'pub(rpc.listProviders)':
|
|
179
|
-
return this.rpcListProviders();
|
|
180
|
-
case 'pub(rpc.send)':
|
|
181
|
-
return this.rpcSend(request, port);
|
|
182
|
-
case 'pub(rpc.startProvider)':
|
|
183
|
-
return this.rpcStartProvider(request, port);
|
|
184
|
-
case 'pub(rpc.subscribe)':
|
|
185
|
-
return this.rpcSubscribe(request, id, port);
|
|
186
|
-
case 'pub(rpc.subscribeConnected)':
|
|
187
|
-
return this.rpcSubscribeConnected(request, id, port);
|
|
188
|
-
case 'pub(rpc.unsubscribe)':
|
|
189
|
-
return this.rpcUnsubscribe(request, port);
|
|
190
|
-
default:
|
|
191
|
-
throw new Error(`Unable to handle message of type ${type}`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/// <reference types="chrome" />
|
|
2
|
-
import type { MessageTypes, TransportRequestMessage } from '../types';
|
|
3
|
-
export default function handler<TMessageType extends MessageTypes>({ id, message, request }: TransportRequestMessage<TMessageType>, port: chrome.runtime.Port, extensionPortName?: string): void;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
// Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { assert } from '@polkadot/util';
|
|
5
|
-
import { PORT_EXTENSION } from "../../defaults.js";
|
|
6
|
-
import Extension from "./Extension.js";
|
|
7
|
-
import State from "./State.js";
|
|
8
|
-
import Tabs from "./Tabs.js";
|
|
9
|
-
const state = new State();
|
|
10
|
-
const extension = new Extension(state);
|
|
11
|
-
const tabs = new Tabs(state);
|
|
12
|
-
export default function handler({
|
|
13
|
-
id,
|
|
14
|
-
message,
|
|
15
|
-
request
|
|
16
|
-
}, port, extensionPortName = PORT_EXTENSION) {
|
|
17
|
-
const isExtension = port.name === extensionPortName;
|
|
18
|
-
const sender = port.sender;
|
|
19
|
-
const from = isExtension ? 'extension' : sender.tab && sender.tab.url || sender.url || '<unknown>';
|
|
20
|
-
const source = `${from}: ${id}: ${message}`;
|
|
21
|
-
console.log(` [in] ${source}`); // :: ${JSON.stringify(request)}`);
|
|
22
|
-
|
|
23
|
-
const promise = isExtension ? extension.handle(id, message, request, port) : tabs.handle(id, message, request, from, port);
|
|
24
|
-
promise.then(response => {
|
|
25
|
-
console.log(`[out] ${source}`); // :: ${JSON.stringify(response)}`);
|
|
26
|
-
|
|
27
|
-
// between the start and the end of the promise, the user may have closed
|
|
28
|
-
// the tab, in which case port will be undefined
|
|
29
|
-
assert(port, 'Port has been disconnected');
|
|
30
|
-
port.postMessage({
|
|
31
|
-
id,
|
|
32
|
-
response
|
|
33
|
-
});
|
|
34
|
-
}).catch(error => {
|
|
35
|
-
console.log(`[err] ${source}:: ${error.message}`);
|
|
36
|
-
|
|
37
|
-
// only send message back to port if it's still connected
|
|
38
|
-
if (port) {
|
|
39
|
-
port.postMessage({
|
|
40
|
-
error: error.message,
|
|
41
|
-
id
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|